I have JSON data files that I’d like to modify somewhat. From:
{
"alpha": "...",
"beta": [ ... ],
"delta": { ... },
"gamma": "..."
}
to:
{
"alpha": "...",
"epsilon" : {
"beta": [ ... ],
"delta": { ... }
},
"gamma": "..."
}
This is, I want to define a subset of fields that I want to extract and move into a new object with a specific name. How do I perform such a task with jq
?
2
Answers
jq '{ alpha, epsilon: { beta, delta }, gamma }' input.json > output.json
Here’s a programmatic way: