jq - like sed for JSON data
stedolan.github.io
stedolan.github.io
- schema definition ( using something like typescript ? )
- data path ( similar to xpath )
- data transformation ( similar to xslt )
i'm pretty sure many people have done their things but i'm still waiting to see a tool like wsdl - based stub generators that would work on many json api.
ps : i know that things like jsonpath and wsdl2 exist, but i really feel like those technologies haven't caught widespread adoption.
Protocol Buffers and JSON have an extremely similar data model. The parts of them that people actually use are effectively identical. The actual differences are minor things like:
- JSON can have arrays of arrays; with Protocol Buffers you need a message in between.
- Protocol Buffers can represent binary data directly; with JSON you have to base64 encode it into a string.
- Protocol Buffers are more specific about the size of integer types (int64 and int32 are different); this allows for more efficient in-memory representations but doesn't matter so much on-the-wire.
I think the two are a match made in heaven.
Dont use JSON if you should use XML.
The reason i'm using JSON is for the fact that's it's fast to parse, compact, and lightweight, compared to XML. Now the reason for needing the xpath/xslt/xsd version of json is not principaly because it's a serialization format, but because it's a serialization format used in almost any modern web API. Experience shows that using JSON for web APIs is a good choice. Saying "you should've used XML" may have been relevant 5 years ago, but i think it's time to assume the fact that JSON is now so much used, that it needs the same kind of tools that xml has had almost from the start.
http://geekandpoke.typepad.com/geekandpoke/2012/03/thank-god...
Something like SQLite work wells for purposes like these.
There is a draft RFC called JSON Schema: core definitions and terminology (draft-zyp-json-schema-04).
> data path ( similar to xpath )
RFC 6901. (JavaScript Object Notation (JSON) Pointer)
curl -s http://tile.openstreetmap.us/vectiles-skeletron/12/656/1582.... | jq '.features[].properties.name'
curl foo/bar.json | jgrep -n -s 'property'
Or even better
curl foo/bar.json | jgrep 'status=500' -n -s 'path'
I've played around with jq and it will definitely become a tool in my toolbox. Kudos to the author.
There's an examples page, if you're struggling to see how it might be useful[2], but I find myself using 'extract', 'find', and 'pluck' on a daily basis.
[1]: https://github.com/ddopson/underscore-cli
[2]: https://github.com/ddopson/underscore-cli/blob/master/Exampl...
However, is it true to say that recs has this functionality? RecordStream is great with sequences of relatively simple JSON structures, where you want to count, group, collate, etc. the sequence. It looks like jq is better able to handle large, complex arbitrary JSON objects, pulling out deeply nested fields and transforming them. For example, how would you implement jq's "recurse" in RecordStream?
Now what would be really cool is using the two tools together :-)
query/transform xml documents from the command line.
Isn't the whole idea of JSON that it exactly serializes most JavaScript objects, and the "right way" to do stuff with it is to just use it like a normal object in your program?
You may not have a program to use the JSON in.
It allows you to use Javascript expressions using a map/filter/reduce paradigm to edit the Json stream, like this:
echo "[1,2,3]" | jsoned -m "' _ * 2 '"
which will print "[2,4,6]"
you can even put the javascript code in files.
Check the wiki (incomplete) for documentation: https://github.com/fabriceleal/Jsoned/wiki/Usage
Anyhow, tangents aside, this looks a really handy tool. Thanks :)