0
When it comes to dealing with network automation, you can find yourself battling with many things, including dealing with XML and JSON data structures as you build apps that consume or spit out data.
Recently I’ve been using ‘jq’ to provide my JSON validation (i.e. I’ve not missed a quotation, colon, comma, curly or square bracket) when building data in JSON. Its primary function and purpose is to search through JSON data to find something in the data set, or reduce the data set to an area of focus, thus also validating your application is generating what it should be generating! A ‘lightweight and flexible command line JSON processor’ if you take the website description which is here: http://stedolan.githib.io/jq/
So how do you use this jq?
Here’s a simple JSON example with an ‘error’.
{
"name":"App1",
"OS":["Linux", "Windows", "Solaris", "OSX"],
"Author":"David Gee",
"Email":"[email protected]",
"Twitter":"@davidjohngee"
"Version":"alpha-v0.1",
"IP_Address":"192.0.2.1:5000"
}
Using ‘jq’ I can not only validate the structure, but in the case of a script, I can also parse out the key/value I need. But first, let’s see where our error is.
$ jq '.' tst.json
parse error: Expected separator between Continue reading