jsawk
jsawk copied to clipboard
extract value from property of json object with non alpha numeric characters
Example json file content in file /tmp/t
[
{
"name:first" : "trevor",
"last" : "wellington",
"from" : "england",
"age" : 52,
"sports" : [ "rugby", "badmitton", "snooker" ]
},
{
"name:first" : "yoni",
"last" : "halevi",
"from" : "israel",
"age" : 26,
"sports" : [ "soccer", "windsurfing" ]
},
{
"name:first" : "cory",
"last" : "parker",
"from" : "united states",
"age" : 31,
"sports" : [ "windsurfing", "baseball", "extreeeeme kayaking" ]
}
]
This works fine
cat /tmp/t | jsawk -n 'out(this.last)'
But this does not
cat test.json | jsawk -n 'out(this.name:first)'
Umm, this has to do with the ":" in the param name. If you replace with an underscore it works. Though, not what you want of course. But that's why it's currently failing in the second test.