Skip to main content

json_studio 0.1.0 copy "json_studio: ^0.1.0" to clipboard
json_studio: ^0.1.0 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.

CI License: MIT Platforms alialperenderici.dev

▶ Try the live demo  ·  see the error marks  ·  dark + search

Tree view Text view with error marks

Dark tree view Dark text view with 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 real code editor (built on re_editor): syntax highlighting, line numbers, code folding, auto-closing brackets, undo/redo.
🔎 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).

Getting started #

dependencies:
  json_studio: ^0.1.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
)

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'))

Migrating from json_editor_flutter #

The most common parameters have the same names, so for many apps it is a drop-in replacement:

// before
JsonEditor(
  json: initialJsonString,
  onChanged: (value) => ...,
  enableMoreOptions: true,
  themeColor: Theme.of(context).colorScheme.primary,
)

// after
JsonStudio(
  json: initialJsonString,
  onChanged: (value) => ...,
  enableMoreOptions: true,
  themeColor: Theme.of(context).colorScheme.primary,
)

Unlike json_editor_flutter, invalid text never throws: onChanged simply is not called until the document is valid again, and onErrorsChanged tells you what is wrong.

Flutter Web notes #

  • Everything is pure Dart/Flutter; the package builds with both the JS and the WebAssembly (--wasm) compilers.
  • For the crispest text, a monospace font such as JetBrains Mono is used when installed; otherwise the platform monospace font is used. Bundle your own and pass JsonStudioTheme(fontFamily: ...) for identical rendering everywhere.
  • Numbers are Dart num: on the web integers above 2^53 lose precision (a JavaScript limitation), and 1.0 is printed as 1. 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
  • Bracket-pair highlighting at the cursor
  • JSON Schema validation
  • Diff view

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.

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.

Text editing is powered by re_editor and re_highlight (MIT).

1
likes
0
points
0
downloads

Publisher

verified publisheralialperenderici.dev

Weekly Downloads

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.

Homepage
Repository (GitHub)
View/report issues

Topics

#json #editor #tree-view #code-editor #web

License

unknown (license)

Dependencies

flutter, re_editor, re_highlight

More

Packages that depend on json_studio