A Flutter package that provides an interactive JSON viewer with features like expanding/collapsing nodes, selecting values, and copying to clipboard. Perfect for debugging, data inspection, and JSON visualization needs.
- 🌳 Interactive tree view of JSON data
- 🔍 Expandable/collapsible nodes for objects and arrays
- ✨ Node selection with highlight
- 📋 Copy to clipboard functionality
- 🎨 Customizable styles for keys and values
- 📊 Visual indicators for array length and object key count
- 🎯 Support for all JSON data types
- 📱 Responsive and scrollable interface
Add this to your package's pubspec.yaml
file:
dependencies:
json_inspector: ^0.0.1
import 'package:json_inspector/json_inspector.dart';
// Your JSON data
final jsonData = {
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "New York"
},
"hobbies": ["reading", "gaming", "cooking"]
};
// Use it in your widget tree
JsonInspector(
jsonData: jsonData,
initiallyExpanded: true, // Optional: expand all nodes initially
)
JsonInspector(
jsonData: jsonData,
initiallyExpanded: false,
keyStyle: TextStyle(
color: Colors.purple,
fontWeight: FontWeight.bold,
),
valueStyle: TextStyle(
color: Colors.green,
),
)
- Click on arrows to expand/collapse nodes
- Use
initiallyExpanded
parameter to control initial state
- Click anywhere on a line to select it
- Long press to copy the value to clipboard
- Visual feedback for selected items
- Arrays show item count:
[3 items]
- Objects show key count:
{2 keys}
- Color-coded keys and values for better readability
- Null values
- Booleans
- Numbers
- Strings
- Arrays
- Objects
import 'package:flutter/material.dart';
import 'package:json_inspector/json_inspector.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final jsonData = {
"user": {
"id": 1,
"name": "John Doe",
"isActive": true,
"favorites": [
"pizza",
"coding",
null
]
}
};
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('JSON Inspector Demo')),
body: JsonInspector(
jsonData: jsonData,
initiallyExpanded: true,
),
),
);
}
}
- Dart SDK: ">=2.17.0 <4.0.0"
- Flutter: ">=3.0.0"
Contributions are welcome! If you find a bug or want a feature, please:
- Open an issue
- Create a pull request with your changes
This project is licensed under the MIT License - see the LICENSE file for details.
-
Clone the repository:
git clone https://github.com/Neelansh-ns/json_inspector.git
-
Install dependencies:
flutter pub get
-
Run the example:
cd example flutter run
Neelansh Sethi
- GitHub: @Neelansh-ns
- Twitter: @neelansh_ns
- Inspired by various JSON viewers in developer tools
- Built with Flutter for the community