A Dart workspace containing JSON parsing tools and applications.
MIT
This workspace contains four packages:
- console_app: A command-line JSON parser that reads from stdin and pretty-prints parse trees
- shelf_app: A server application using the
shelf
package and Docker - shared_lib: A Dart library for parsing JSON with token-based representation and pretty-printing
- dart_frog_app: A server application using the
dart_frog
framework that exposes the same JSON parsing API
- Dart SDK >= 3.9.2
- Docker
- Melos
# From the root directory
dart pub get
Format all Dart code in the workspace:
dart format .
Run static analysis on all packages:
dart analyze .
This workspace uses Melos to manage multi-package tasks. Prefer the Melos scripts below for day-to-day development and CI.
Bootstrap the workspace (install package dependencies for all packages):
# From the repo root
dart pub get
dart run melos bootstrap
Build workspace executables (replaces bin/build_all
):
dart run melos run build
Run all package tests:
dart run melos exec -- "dart test -r expanded --chain-stack-traces"
Run the CI test script to produce a combined LCOV report at coverage/lcov.info
:
dart run melos run test:ci
The console app provides a command-line JSON parser.
# Enter JSON into the console app
./out/console_app
# Example: pipe JSON to the console app
echo '{"name": "John", "age": 30}' | ./out/console_app
The server apps provide a REST API for JSON parsing. You can test them using the REST Client VS Code extension.
- Install the REST Client extension for VS Code
Start the Shelf-based server (existing implementation):
dart run melos run run:shelf
Start the Dart Frog dev server (development-friendly):
dart run melos run run:dart_frog
-
Create
.rest
files in thetestdata/
folder at the root of the workspace -
Write HTTP requests in the following format (both servers expose the same endpoint):
POST http://localhost:8000/api/v1/parse
Content-Type: text/plain
{"key": "value", "number": 42}
- Click the "Send Request" link above the request to execute it
POST http://localhost:8000/api/v1/parse
Content-Type: text/plain
{"name": "John", "age": 30, "items": [1, 2, 3]}
POST http://localhost:8000/api/v1/parse
Content-Type: text/plain
[1, "hello", null, true, {"nested": "object"}]
POST http://localhost:8000/api/v1/parse
Content-Type: text/plain
{"invalid": json}
POST http://localhost:8000/api/v1/parse
Content-Type: application/json
{"key": "value"}
- Success (200): Returns the parsed JSON as
application/json
- Parse Error (400): Returns
{"code": 400, "message": "error details"}
- Unsupported Media Type (415): Returns
{"code": 415, "message": "Unsupported Media Type"}