jsawk icon indicating copy to clipboard operation
jsawk copied to clipboard

extract value from property of json object with non alpha numeric characters

Open low-decarie opened this issue 10 years ago • 1 comments

StackOverflow question

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)'

low-decarie avatar Nov 02 '14 00:11 low-decarie

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.

flamusdiu avatar Nov 02 '14 10:11 flamusdiu