Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 524

JQ Cannot iterate over null

$
0
0

I am trying to create a jq that is dynamic in returning data.User Story: I have data with many fields and not named like I want. I want to be able to based on the data and schema transform the data.

Example:JSON

"inputArray": [    {"objective_id": "ac-1_obj.a-1","description": "an access control policy is developed and documented;","framework_id": 1,"domain_id": "ac","domaintitle": "Access Control","id": 0,"control_id": "ac-1","controltitle": "Policy and Procedures"    },    {"objective_id": "ac-1_obj.a-2","description": "the access control policy is disseminated to {{ insert: param, ac-01_odp.01 }};","framework_id": 1,"domain_id": "ac","domaintitle": "Access Control","id": 0,"control_id": "ac-1","controltitle": "Policy and Procedures"    },    {"objective_id": "ac-1_obj.a-3","description": "access control procedures to facilitate the implementation of the access control policy and associated controls are developed and documented;","framework_id": 1,"domain_id": "ac","domaintitle": "Access Control","id": 0,"control_id": "ac-1","controltitle": "Policy and Procedures"    }  ],"schema": [    { "new": "objective", "input": "objective_id" },    { "new": "framework", "input": "framework_id" },    { "new": "control", "input": "control_id" },    { "new": "title", "input": "controltitle" },    { "new": "description", "input": "description" }  ]}

JQ

  inputArray: [    .inputArray[] |    reduce (.schema[] | {new: .new, input: .input}) as $map (      {};       .[$map.new] = .[$map.input]    )  ]}

Error

jq: error (at /tmp/data.json:40): Cannot iterate over null (null) undefined
  • schema is what it seems to be mad about.
  • I have tested that .schema is available
  • I have added ? to the end of .schema and values are emptyjq kung fu playground

Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>