A project to study jq by re-implementing it in C# 9.0/.NET 5.0 as a compiler-to-object-graphs (is there a better name for the object oriented version of compilation to closure trees?).
Visit jsonmasher.mbrezu.me for a web playground.
To get started with using JsonMasher in your own projects, look at the "end to end" tests, for instance Simple.cs. "End to end" in this case means it tests both the compiler and the resulting object tree.
The most important interface: IJsonMasherOperator.cs.
Json representation used internally: Json.cs. System.Text.Json
JsonElement
/JsonDocument
can be converted to Json
, and Json
can be pretty printed. Did not
add a conversion for Newtonsoft Json to avoid the extra
dependency, but it shouldn't be hard to add.
A CLI interface project is JsonMasher.Cli.
A Web UI project is JsonMasher.Web.
Some simple benchmarks in JsonMasher.Benchmarks.
Short answer:
- some jq features; most notably, modules (see the TODO link below)
- debugging facilities (
debug
is there, but I want more)
Long answer: TODO JQ manual. Also see examples in jsonmasher.mbrezu.me for what is implemented.
With the simple benchmarks in JsonMasher.Benchmarks, it seems that JsonMasher is about 1.5-2 times slower than jq, but these are only a handful of microbenchmarks...
I made no attempt at optimization and instead wrote the simplest code I could. So the performance seems surprisingly good to me, so far. I guess this means the JIT people did an amazing job :-)
Possible issues:
- some allocations that could be eliminated (e.g. for the simplest case of variable binding);
- use of exceptions for
try/catch
,label/break
and?//
.
2-clause BSD, see the LICENSE file.