json_studio 0.2.1
json_studio: ^0.2.1 copied to clipboard
A modern JSON editor for Flutter with tree and text views, search, code folding and precise bracket error marks. Works on web, mobile and desktop.
json_studio
A modern, fast JSON editor for Flutter.
Tree view and text view, search, code folding and precise bracket error marks.
Works on Web, Android, iOS, macOS, Windows and Linux.
▶ Try the live demo · see the error marks · dark + search
Live demo #
The live demo is the
example/ app compiled for the web. Try this: switch to Text,
press Broken sample to see the unclosed and mismatched brackets underlined,
click an error in the status bar to jump to it, then press Ctrl/⌘ + F.
It is deployed automatically from main.
Run it locally:
cd example
flutter run -d chrome
Why json_studio? #
Editing configuration JSON in a back-office or admin panel usually means a plain
text box or a tree widget with no way to find things. json_studio gives you
both in one widget, with the features you actually miss:
| 🌳 Tree view | Collapse/expand any block, edit keys and values inline, add / delete / duplicate / reorder, change a node's type, copy its path or value. Virtualized, so large documents stay smooth. |
| 📝 Text view | A built-in JSON code editor: syntax highlighting, line numbers, code folding, auto-closing brackets, matching-bracket highlight, undo/redo. Only visible lines are rendered. |
| 🔎 Search in both views | Keys and values, case sensitive, regular expressions, next/previous match, match counter. Ctrl/⌘ + F, F3. |
| 🚨 Precise error marks | Every unclosed, unexpected or mismatched bracket is underlined in the text, flagged in the gutter and listed in the status bar. Click an error to jump to it. |
| ⚡ Reliable on Web | Error positions come from the package's own parser, not from jsonDecode (whose FormatException.offset is not available when compiled with dart2js). |
| 🎨 Modern UI | Light and dark themes derived from your ThemeData, fully customizable. Responsive toolbar. |
| 🌍 Localizable | All texts live in JsonStudioLabels (Turkish preset included). |
| 🪶 No dependencies | Nothing but the Flutter SDK. |
Getting started #
dependencies:
json_studio: ^0.2.0
import 'package:json_studio/json_studio.dart';
SizedBox(
height: 480,
child: JsonStudio(
json: '{"name": "Alperen", "tags": ["flutter", "dart"]}',
onChanged: (value) => debugPrint('valid JSON: $value'),
),
)
JsonStudio fills the space it is given, so put it in a SizedBox, Expanded
or a dialog with a bounded height.
json accepts either a JSON text (String) or an already decoded value
(Map, List, ...). onChanged receives the decoded value and is only called
when the document is valid.
Using a controller #
Create a JsonStudioController when you want to drive the editor from outside:
class _MyState extends State<MyWidget> {
late final controller = JsonStudioController(json: initialJson);
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(children: [
TextButton(onPressed: controller.format, child: const Text('Format')),
TextButton(onPressed: controller.minify, child: const Text('Minify')),
TextButton(
onPressed: () => controller.setMode(JsonStudioMode.text),
child: const Text('Text'),
),
TextButton(
// Only save when the document is valid.
onPressed: controller.isValid ? () => save(controller.value) : null,
child: const Text('Save'),
),
]),
Expanded(child: JsonStudio(controller: controller)),
],
);
}
}
| Member | Description |
|---|---|
value |
Last valid decoded value (Map, List, ...). |
text |
Current text exactly as typed. |
isValid / isEmpty / diagnostics |
Validity and the list of JsonDiagnostic (message, line, column). |
setText(String) / setJson(Object?) |
Replace the whole document, e.g. after loading from a server. |
format() / minify() / sortKeys() |
Transform a valid document. |
setMode(JsonStudioMode) / toggleMode() |
Switch between tree and text. |
expandAll() / collapseAll() |
Expand/collapse the tree, or unfold/fold the text. |
openSearch() / setQuery(String) / nextMatch() |
Drive the search from code. |
undo() / redo() |
History. |
updateValue / renameKey / addChild / removeAt / duplicate / moveUp / moveDown / changeType |
Programmatic tree edits, addressed by JsonPath. |
goToDiagnostic(JsonDiagnostic) |
Jump to an error in the text view. |
Callbacks #
JsonStudio(
json: text,
onChanged: (value) {}, // valid documents only, decoded value
onTextChanged: (text) {}, // every change, valid or not
onErrorsChanged: (errors) {}, // empty list = valid
)
Invalid text never throws: onChanged is simply not called until the document
is valid again, and onErrorsChanged tells you what is wrong.
Options #
JsonStudio(
json: text,
mode: JsonStudioMode.tree, // initial view
readOnly: false,
showToolbar: true,
showStatusBar: true,
enableMoreOptions: true, // Format / Minify / Sort keys in the menu
showLineNumbers: true,
wordWrap: false,
indent: 2,
initialExpandDepth: 1,
themeColor: Colors.indigo, // accent color (or pass a full `theme:`)
labels: const JsonStudioLabels.turkish(),
toolbarActions: [IconButton(onPressed: save, icon: const Icon(Icons.check))],
)
Theming #
By default the editor follows Theme.of(context) (light or dark) and uses
colorScheme.primary as the accent. For full control:
JsonStudio(
json: text,
theme: JsonStudioTheme.dark(accent: Colors.tealAccent).copyWith(
radius: 16,
fontFamily: 'JetBrains Mono',
keyColor: Colors.lightBlueAccent,
),
)
Localization #
JsonStudio(labels: const JsonStudioLabels.turkish())
// or override single strings
JsonStudio(labels: const JsonStudioLabels(tree: 'Baum', text: 'Text'))
Flutter Web notes #
- Everything is pure Dart/Flutter; the package builds with both the JS and the
WebAssembly (
--wasm) compilers. - On desktop and mobile an installed monospace font such as JetBrains Mono
or Menlo is used. Browsers do not give Flutter access to installed fonts, so
on the web bundle one and pass
JsonStudioTheme(fontFamily: ...). - Numbers are Dart
num: on the web integers above 2^53 lose precision (a JavaScript limitation), and1.0is printed as1. This only matters if you edit such values in the tree; the text view never rewrites your text.
Limitations #
- Besides all bracket problems, only the first syntax error is reported at a time (fix it and the next one appears).
- Editing in the tree re-formats the document with the configured
indent(key order is preserved). - While the text is invalid the tree keeps showing the last valid version, read-only, with a banner linking to the error.
Roadmap #
- Side-by-side tree + text layout
- JSON Schema validation
- Diff view
- Follow Flutter's split of
package:flutter/material.dartandpackage:flutter/cupertino.dart(deprecated in newer SDKs in favour ofmaterial_ui/cupertino_ui) once the migration path is settled
Ideas and pull requests are welcome — please open an issue.
Türkçe özet #
json_studio, Flutter için (Web dahil tüm platformlarda çalışan) modern bir JSON
editörüdür. Ağaç ve metin görünümü, her iki görünümde arama (regex
dahil), blokları katlama/açma, hatalı veya eksik parantezlerin kırmızı
işaretlenmesi ve Türkçe arayüz desteği (JsonStudioLabels.turkish()) sunar.
JsonStudio(
json: jsonMetni,
labels: const JsonStudioLabels.turkish(),
onChanged: (deger) => print(deger), // yalnızca geçerli JSON'da çağrılır
)
Author #
Built with care by Ali Alperen Derici.
- 🌐 Website: alialperenderici.dev
- 🐙 GitHub: @alperenderici
- ☕ Support: buymeacoffee.com/alperenderici
If json_studio saves you time, a ⭐ on
GitHub and a like on pub.dev
mean a lot. Need a Flutter app or admin panel built? Get in touch via
alialperenderici.dev.
License #
MIT — see LICENSE.
