I have the following json file:
{
"data": {
"allPost": {
"edges": [
{
"node": {
"slug": "fp-cheat-sheet",
"labels": [
"FUNCTIONAL PROGRAMMING",
"HASKELL",
"SCALA"
]
}
},
{
"node": {
"slug": "nlp-101",
"labels": [
"DATA SCIENCE",
"NLP",
"PYTHON"
]
}
}
]
}
}
}
I am writing a shell script to extract info for each edge
, using JQ. From each edge
, which is an array, I am able to extract slugs
which is a string, but not labels
which is again an array:
readarray -t slugs < <(cat ${json_file_name} | jq .data.allPost.edges[].node.slug)
readarray -t tags < <(cat ${json_file_name} | jq .data.allPost.edges[].node.labels)
echo ${slugs[1]}
# successfully prints '"nlp-101"'
echo ${tags[1]}
# wrongly prints '"FUNCTIONAL PROGRAMMING",'
I want to extract labels for each post and print it in a file in the exact same format. e.g. for echo ${tags[1]}
I want it to print:
["DATA SCIENCE", "NLP", "PYTHON"]
How can I fix the above code to extract labels from the above JSON as desired?