skip to Main Content

How can i select / filter all connection with field.usesEncryption is true using jq from JSON data below

{
  "connections": {
    "connection": [
      {
        "field": [
          {
            "id": "url",
            "encryptedValueSet": false,
            "usesEncryption": false,
            "componentOverride": false,
            "useDefault": false
          },
          {
            "id": "user",
            "encryptedValueSet": false,
            "usesEncryption": false,
            "componentOverride": false,
            "useDefault": false
          },
          {
            "id": "password",
            "encryptedValueSet": true,
            "usesEncryption": true,
            "componentOverride": false,
            "useDefault": false
          }
        ],
        "id": "3ea89002-51f5-4369-9539-63c3bd406a64"
      }
    ]
  }
}

I tried following but not working as desired

jq '. | select(.connections.connection[].field[] | .usesEncryption==true)' EnvironmentExtensions.json
jq '. | .connections.connection[].field[] | select(.usesEncryption==true)' EnvironmentExtensions.json

2

Answers


  1. Chosen as BEST ANSWER

    Filter below works but the top level structure is lost from output

    jq '.connections.connection[].field[] | select(.usesEncryption)' EnvironmentExtensions.json
    

  2. To modify the inner array, either use (requires jq 1.7):

    .connections.connection[].field[] |= select(.usesEncryption)
    

    or (works with jq 1.6)

    .connections.connection[].field |= map(select(.usesEncryption))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search