3 ms·
For a much simpler solution to the json graph problem: https://github.com/jsog/jsog https://github.com/jsog/jsog Implementations in Javascript, Python, Ruby,
by stickfigure 11y ago
For a much simpler solution to the json graph problem:
https://github.com/jsog/jsog https://github.com/jsog/jsog
Implementations in Javascript, Python, Ruby, and Java.
- arxpoetica 11y agoHonest question, how is it simpler?
- latchkey 11y agoOne simple metric would be the number of lines of code: https://github.com/jsog/jsog/blob/master/src/JSOG.coffee https://github.com/jsog/jsog/blob/master/src/JSOG.coffee
- deleted 11y ago[deleted]
- stickfigure 11y agoThere are no paths to evaluate, just unique synthetic ids. The JSOG transmutation process is a simple recursive function; most of the implementations are just a handful of lines of code.
- TillE 11y agoInteresting. That looks very similar to YAML's anchor/alias feature.
- 21echoes 11y agoI much prefer the JSON-API approach by Yehuda Katz, et al.[1] https://gist.github.com/21echoes/a1ca3e4376262da32297 https://gist.github.com/21echoes/a1ca3e4376262da32297 It's definitely designed to be used in a RESTful-esque situation (the reference keys are a type/id tuples), but that's the dominant JSON use case anyway. For an example of why you'd want type/id tuples over JSOG's plain string @id -- while in the given JSOG example, all items are People, referencing an Address object from Sally (so that Bob can deliver her gift) introduces a potential conflict between Address @id: 1 and Person @id: 1. To disambiguate, you could of course prefix all "@id" value strings with e.g. "address-" or "person-", but then you've just re-invented JSON-API's solution, while making your @id not a real id (not usable in cases like e.g. `api.example.com/resource/<id>`, etc.). The other solution is to say that JSOG @id's are only for use in one response parsing situation, and could be discarded afterwards. But that seems like quite a waste -- what if e.g. your API wanted to be able to send @id references over the wire without the overhead of sending the whole referenced object? [1]http://jsonapi.org/ http://jsonapi.org/
- stickfigure 11y agoJSOG solves one particular, widespread problem - reconstituting an object graph on the other side of a wire. As you said, the information is only meaningful during the exchange. JSOG isn't trying to solve some greater notion of object identity; that's your application's business.
- javajosh 11y agoI agree that the type/id pair is quite helpful when reading the graph! Interestingly, this does have the effect of limiting you to N top-level types, but I don't actually think that's a big deal. Most applications, if you break them down, only have like 3 real types (one of which is always "user").
- dustingetz 11y agoalso https://github.com/cognitect/transit-format https://github.com/cognitect/transit-format