Closed niedzielski closed 5 years ago
This is a good point. To encode all of JSON correctly, a tree language grammar is needed, for this space reason and for other issues like parsing 2 vs “2”.
Someone I believe is writing a JSON tree language. I expect it to be available by end of this month.
But regardless, the method names as is are wrong and we should rename them in the next release. Something like “toJsonish”, to convey the uncertainty. Or perhaps we could define a JSON subset that excludes the language features that plain tree can’t support and then rename the methods to indicate that, something like “toJsonLite”.
I’ve found these methods to be very helpful in practice in most situations but right now they aren’t doing quite what they say they do which is unacceptable.
Just to clarify: I don't much about Tree Notation. I just saw the comparison to a package.json file and the toJson() text area in the sandbox. Depending on the project goals, this issue may be resolved by documentation tweaks. However, I would guess that JSON mapping would be useful if only to ensure Tree Notation can solve all problems JSON can.
Fresh eyes are very helpful! Thank you for pointing that out. Will definitely fix and adjust and have it out in a few days.
A redditor pointed out:
You seem to have no spec. How would one even encode whitespace or newlines in keys or values? Is the order of children meaningful? In JSON, it's simple: no for objects, yes for arrays. But tree notation doesn't have arrays. In your example on your website, you show a package.tree and a package.json which is presumably the equivalent. From that, one would assume that tree notation nodes are
So the readme should also be clarified that it's not a 1-to-1 relationship.
We've changed the method to toJSONSubset for now and updated the Readme. When someone is done with a JSON Tree Language we will add a link or add it to this repo and close this issue.
Here is a language that compiles to JSON: http://treenotation.org/sandbox/build/#standard%20dug
I am closing this issue for now. There is still room for improvement (once we have a fun JSON tree language, probably using pattern matching), but hopefully the improvements made to date are a good enough improvement.
I typed out the following JSON in the sandbox:
Which converted to the following tree:
However, that tree converts back to the following JSON:
This JSON differs from the input.
I don't know if this only an issue with whitespaces but there seems to be some inconsistency or incompatibility when mapping between the two.