I have a JSON that I am trying to process. I am using jq and can't for my life get the required output.
I have a simple eg below,
{
"message" :"{ \"foo\": \"42\", \"bar\": \"less interesting data\"}"
}
My Build Up
jq '."message"
{
"message" :{"foo": "42", "bar": "less interesting data"}
}
gives
{
"foo": "42",
"bar": "less interesting data"
}
."message"."bar"
gives
"less interesting data"
So
{
"message" :"{"foo": "42", "bar": "less interesting data"}"
}
FAILS as JSON invalid
{
"message" :"{\"foo\": \"42\", \"bar\": \"less interesting data\"}"
}
FAILS 'jq: error (at :3): Cannot index string with string "bar" exit status 5'
I have tried a whole bunch of differing jq queries (i won't waste your time listing them)
So I would like some advice on how id get "bar" from the JSON
It's not a duplicate of convert string to JSON as this leads you to the idea of conversion. Without this question, you'd never know the answer is to use fromjson