Output is to standard out, or a file specified by the --outfile switch. Input is from either standard in, or from a file if using the --file switch
It looks like both the JavaScript version and the new Python C# wrapper have equivalent CLI tools as well.I can see potential usefulness of this is in debug mode APIs, where somehow comments are sent as well and are rendered nicely. Especially useful in game dev jsons.
country: no
As equivalent to a boolean falsy value: country: false
It is a relatively common source of problems. One solution is to escape the value: country: “no”
More context: https://www.bram.us/2022/01/11/yaml-the-norway-problem/Yaml - just say Norway
Both objects desugar to a sequence of segments (lines).
The result is that you can freely mix expression/assignment blocks & statements. Things like switch-case blocks & macro tables are suddenly trivial to format in 2d.
Because comments are handled as right floating, all comments nicely align.
I vibe coded the base layer in an hour. I'm using with autogenerated code, so output is manually coded based on my input. The tricky bit would be "discovering" tables & block. I'd jus use a combo of an LSP and direct observation of sequential statements.
There's an older pure Python version but it's no longer maintained - the author of that recently replaced it with a Python library wrapping the C# code.
This looks to me like the perfect opportunity for a language-independent conformance suite - a set of tests defined as data files that can be shared across multiple implementations.
This would not only guarantee that the existing C# and TypeScript implementations behaved exactly the same way, but would also make it much easier to build and then maintain more implementations across other languages.
Interestingly the now-deprecated Python library does actually use a data-driven test suite in the kind of shape I'm describing: https://github.com/masaccio/compact-json/tree/main/tests/dat...
That new Python library is https://pypi.org/project/fractured-json/ but it's a wrapper around the C# library and says "You must install a valid .NET runtime" - that makes it mostly a non-starter as a dependency for other Python projects because it breaks the ability to "pip install" them without a significant extra step.
{
foo: "bar",
ans: 42,
comments: {
ans: "Douglas Adams"
}
}
damnitbuilds•1h ago
And BTW, thanks for supporting comments - the reason given for keeping comments out of standard Json is silly ( "they would be used for parsing directives" ).
Xymist•1h ago
A flathead screwdriver should bend like rubber if someone tries to use it as a prybar.
nodja•38m ago
I don't disagree with the choice, but seeing how things turned out I can't just help but look at the greener grass on the other side.
libria•32m ago
Better not let me near your JSON files then. I pound in wall anchors with the bottom of my drill if my hammer is not within arms reach.
mystifyingpoi•30m ago
While I admire his design goals, people will just work around it in a pinch by adding a "comment" or "_comment" or "_comment_${random_uuid}", simply because they want to do the job they need.
If your screwdriver bends like a rubber when prying, damn it, I'll just put a screw next to it, so it thinks it is used for driving screws and thus behaves correctly.
patates•1h ago
I also would have wanted comments, but I see why Crockford must have been skeptical. He just didn't want JSON to be the next XML.
frizlab•1h ago
cromulent•16m ago
> Insignificant whitespace is allowed before or after any token.
frizlab•8m ago