jq convert 2D array JSON to array with objects

Verified Environment Version OS Ubuntu 20.04.5 LTS jq jq-1.6 What to do Note https://stedolan.github.io/jq/manual/ –slurp/-s: Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once. to_entries, from_entries, with_entries These functions convert between an object and an array of key-value pairs. If to_entries is passed an object, then for each k: v entry in the input, the output array includes {"key": k, "value": v}....

March 5, 2023

Avoid "argument list too lang" error when using jq in bash

Verified Environment Version OS Ubuntu 20.04.5 LTS jq jq-1.6 Why is the error occurring? If you run the following scripts in bash, you will get bash: /usr/bin/jq: Argument list too long error. array=$(echo "[" $(echo {1..1000000} | tr ' ' ',') "]") echo '{"array": null}' | jq --arg array "${array}" '.array = $array' This is thought to be because when --arg array "${array}" is used, ${array} is variable expanded and thus exceeds ARG_MAX....

February 5, 2023