[GTALUG] Extracting data from JSON file

William Park opengeometry at yahoo.ca
Sat Jul 20 00:01:34 EDT 2019


On Fri, Jul 19, 2019 at 01:06:05PM -0400, Lennart Sorensen via talk wrote:
> On Fri, Jul 19, 2019 at 03:40:29AM -0400, William Park via talk wrote:
> > How do you extract data from JSON file?
> > 
> > For XML file, "xmlstarlet" is the tool you try first.  Is there similar
> > tool for JSON format?  I tried "jq" today, but its syntax is a bit weird
> > from first look.
> 
> python:
> 
> https://docs.python.org/3/library/json.html
> 
> c:
> 
> https://github.com/vincenthz/libjson
> https://github.com/json-c/json-c
> 
> etc.  There are lots.
> 
> jq looks decent if you have some reason to want a command line tool
> for it.  I haven't tried it.  I have only ever wanted to deal with json
> data in an application.  Fortunately. :)

I'm writing automated test scripts.  Unfortunately for me, input
configuration is XML, and I use "xmlstarlet" to get data from that.  The
output is JSON, and I need to extract data from that to say "Pass" or
"Fail".

Looks like "jq" is the answer.  But, I find that "jq" ignores duplicate
keys, and accepts only the last one.  Major pain!
-- 
William Park <opengeometry at yahoo.ca>


More information about the talk mailing list