1

I would like to transform with jq this JSON

[
  {
    "one": 37,
    "two": "2017-09-15T19:31:55"
  }
]

to this one

[
  {
    "one": 37
  },
  {
    "two": "2017-09-15T19:31:55"
  }
]

How to do it?

Thank you

1 Answer 1

1

When it comes to manipulations involving the keys of JSON objects, to_entries (and its friend, with_entries) are your friends:

map(to_entries[] | {(.key): .value})

Note also the parentheses around .key.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I'm becoming mad, because I had no idea of (.key) to print the value of key as key of output object. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.