I have a json file as below
{
"requestData": {
"username": "admin"
},
"eventTime": "2023-12-01T23:50:02.554+0000",
"observer": {
"id": "target"
}
I want to get only the below output side by side,O/P
"username": "admin","eventTime": "2023-12-01T23:50:02.554+0000"
I tried using below but, able to get only one record at a time, how to nest both and get above output
cat filename | jq '.requestData.username'
}
2
Answers
The following should give you exactly what you want:
If you just want the values:
Or, if you want to use string interpolation as Jeff suggests:
Not pretty, but building an array first, then joining the json-encoded values on colon, followed by a join on comma:
Output: