I can’t access the values in the json file.
Can be a bug for labels like numerics? Or I wrong to use jq? Can you help me?
Below json sample
Sorry for my English, txs
{
"datasets":{
"0":
{
"0": { "0":11, "1":11,"2":10 },
"1": { "0":73, "1":77, "2":87 },
....,
....,
"n":{ "0":1027, "1":1025, "2":1020 }
},
"1":
{
"0": { "0":8, "1":7, "2":12 },
"1": { "0":69, "1":75, "2":77 },
....,
....,
"n":{ "0":1026, "1":1026, "2":1025 }
},
....,
....,
"99":
{
"0": { "0":9, "1":9, "2":10 },
"1": { "0":77, "1":76, "2":75 },
....,
....,
"n":{ "0":1010, "1":1011, "2":1011 }
},
},
"other_label":{
.....
}
}
I used jq command following manual but unsuccessfully. If I run:
jq .datasets
command is executed without problem. But if I add ."0" or .0 then results in:
jq: error: syntax error, unexpected LITERAL, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
>Solution :
Like the error message says, it’s a shell quoting issue. Given this input file:
{
"datasets":{
"0":
{
"0": { "0":11, "1":11,"2":10 },
"1": { "0":73, "1":77, "2":87 },
"n":{ "0":1027, "1":1025, "2":1020 }
},
"1":
{
"0": { "0":8, "1":7, "2":12 },
"1": { "0":69, "1":75, "2":77 },
"n":{ "0":1026, "1":1026, "2":1025 }
},
"99":
{
"0": { "0":9, "1":9, "2":10 },
"1": { "0":77, "1":76, "2":75 },
"n":{ "0":1010, "1":1011, "2":1011 }
}
},
"other_label":{
}
}
I can run this command line:
jq '.datasets."0"' data.json
And get this output:
{
"0": {
"0": 11,
"1": 11,
"2": 10
},
"1": {
"0": 73,
"1": 77,
"2": 87
},
"n": {
"0": 1027,
"1": 1025,
"2": 1020
}
}
You need the outer quotes so that the quotes around "0"
are actually seen by jq
.