Home > Mobile >  jq query not working in expected behaviour
jq query not working in expected behaviour

Time:09-17

{
  "data": {
    "AWS_ACCESS_KEY_ID": "topsecret",
    "AWS_SECRET_ACCESS_KEY": "s3cr3t"
  },
  "metadata": {
    "created_time": "2022-09-16T06:49:11.45818Z",
    "deletion_time": "",
    "destroyed": false,
    "version": 23
  }
}

I've above data and I want my input as:

"data": {
    "AWS_ACCESS_KEY_ID": "topsecret",
    "AWS_SECRET_ACCESS_KEY": "s3cr3t"
  }

jq query like this jq .data file.json is only giving me output like this:

{
  "AWS_ACCESS_KEY_ID": "topsecret",
  "AWS_SECRET_ACCESS_KEY": "s3cr3t"
 }

Please help.

CodePudding user response:

Are you sure you want invalid json? You can preserve the key if you enclose it in curly braces, e.g.:

jq '{ data }'

Output:

{
  "data": {
    "AWS_ACCESS_KEY_ID": "topsecret",
    "AWS_SECRET_ACCESS_KEY": "s3cr3t"
  }
}

Note that the above is a shorthand for { "data": .data }

  • Related