2

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: {
}
John Bergqvist
  • 852
  • 13
  • 38

1 Answers1

3

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": {}
}
chepner
  • 497,756
  • 71
  • 530
  • 681
Devstr
  • 4,431
  • 1
  • 18
  • 30
  • You misunderstand, config.name is the property within the json file that I want the object to be named after. I've updated the OP. – John Bergqvist Feb 12 '18 at 11:46