I am working on an assignment about parsing JSON by shell script. Is there any way that I can get the values from the JSON when executing it? For example, I'like to output id, body, and age's value. I am trying to use cut, sed, grep, but not jq. Should I use for-loop? Currently, I only can redirect the json to a txt file.
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "[email protected]",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora",
"age": 28
}
jqis the right tool for the job. Why aren't you using it?sedandgrepare both regular-expression-based, and therefore not capable of parsing things like JSON that can contain nested syntax (e.g. JSON allows arrays within arrays within arrays within....). It's in the same category as HTML. You can fake it if the JSON is simple enough, but parsing JSON with regex will fail if the JSON isn't in the exact format you expect.sedandgrepcan not doing like remove the bracket, comma, and the keys. Then only leaves those values?