micha / jsawk

Like awk, but for JSON.
1.39k stars 96 forks source link

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

Open low-decarie opened 9 years ago

low-decarie commented 9 years ago

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

flamusdiu commented 9 years ago

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.