Following on from prior posts, a bit more tinkering with JQ, this time formatting the output.
So here's my starting point, a JSON document: -
simpsons.json
[
{
"givenName": "Maggie",
"familyName": "Simpson"
},
{
"givenName": "Lisa",
"familyName": "Simpson"
},
{
"givenName": "Marge",
"familyName": "Simpson"
},
{
"givenName": "Homer",
"familyName": "Simpson"
},
{
"givenName": "Bart",
"familyName": "Simpson"
}
]
and here's my going through it and formatting the output: -
cat simpsons.json | jq -r '.[] | {"Given Name": .givenName, "Family Name": .familyName}'
{
"Given Name": "Maggie",
"Family Name": "Simpson"
}
{
"Given Name": "Lisa",
"Family Name": "Simpson"
}
{
"Given Name": "Marge",
"Family Name": "Simpson"
}
{
"Given Name": "Homer",
"Family Name": "Simpson"
}
{
"Given Name": "Bart",
"Family Name": "Simpson"
}
and here's an example, searching for given names beginning with "M" and then formatting the output: -
cat simpsons.json | jq -r '.[] | select(.givenName | startswith("M")) | {"Given Name": .givenName, "Family Name": .familyName}'
{
"Given Name": "Maggie",
"Family Name": "Simpson"
}
{
"Given Name": "Marge",
"Family Name": "Simpson"
}
No comments:
Post a Comment