json_sorter
1.0.0, released 6 years ago by dartside.dev
Command-line tool and encoder that sorts JSON maps by key.
What it does
Provides a CLI to sort JSON files in-place and a JsonSortedEncoder that recursively sorts map keys before encoding. It supports custom indentation and works with any JSON-serializable object.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to keep JSON files sorted for consistency across a team.
- You want all JSON output from your Dart app to be deterministic and sorted.
- You want a quick way to sort a JSON file from the command line during CI.
- You need a lightweight dependency that adds no build‑time code generation.
Skip it when
- You require complex custom serialization logic beyond key sorting.
- You need to sort data structures that are not JSON maps (e.g., custom objects).
Strengths
- Zero dependencies beyond args.
- Simple CLI and encoder API.
- Supports custom indentation.
- Works with Dart SDK 2.12+ and all platforms.
Weaknesses
- Only sorts map keys; does not handle custom object serialization.
- No support for sorting lists or other data structures.
- Limited to JSON; not a general-purpose data transformer.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
import 'package:json_sorter/json_sorter.dart';
const encoder = JsonSortedEncoder.withIndent(' ');
const data = {'b': true, 'a': false};
print(encoder.convert(data));Alternatives
Packages that do the same job and could replace json_sorter.
- cli_util
Utilities to help build Dart command-line apps, find the SDK, and display progress.
93Compare - cli_tools
Utilities for building command‑line interfaces, including argument parsing, analytics, and progress reporting.
83Compare - config
Typed CLI argument and config file parser with env support
83Compare - json_schema
Validate JSON data against JSON Schema drafts in Dart.
63Compare
Works with
Packages commonly used together with json_sorter: ones it builds on, ones built on it, and its own family.