jq seems to parse string values as json #3067
-
Hello. It seems that jq tries to parse some string values as JSON objects. For example, with the following text, the filed "Text" is parsed as a JSON, and it is not With this text put into a file, it works using the command :
When the field "Text" value is something like "{a=1, b=2}" (that is not a JSON object, but just a string, in fact a java Properties.toString), and with the same command, the parser fails with these messages :
Strange no ? Does someone know if this is a normal behavior, and if some flag may be used to disable it, or if it's a "little bug" ? Thanks for your help. I use jq version jq-1.5-1-a5b5cbe |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
This is not a bug. The for loop splits by white spaces. json='[ { "Key": "one", "{a=1, b=2}": "ok" }, { "Key": "two", "Text": "ok" } ]'
for x in $(echo "$json" | jq -c '.[]'); do printf "[[[%s]]]\n" "$x"; done
The first input while read -r x; do jq . <<< "$x"; done < <(echo "$json" | jq -c '.[]')
while read -r -d '' x; do jq . <<< "$x"; done < <(echo "$json" | jq --raw-output0 '.[]') |
Beta Was this translation helpful? Give feedback.
This is not a bug. The for loop splits by white spaces.
The first input
{"Key":"one","{a=1,
is not a valid JSON. If you use the compact output option-c
, you can read each line, or you can also use--raw-output0
option introduced in 1.7.