If I have a json file as follows:
{
config: {
name: "test1"
}
}
How would I use jq
to create an empty object named after "test1" in a new file?
i.e.
test1: {
}
If I have a json file as follows:
{
config: {
name: "test1"
}
}
How would I use jq
to create an empty object named after "test1" in a new file?
i.e.
test1: {
}
First I suggest you make original file a proper JSON by adding quotes to keys:
{
"config": {
"name": "test1"
}
}
Now you can do it like this:
jq '{(.config.name):{}}' config.name
Output:
{
"test1": {}
}