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

How to clear all object keys's value in jq

$
0
0

I want to clear all values from "dependencies" by using jq:

json_string="$(cat <<'END'{"name": "hello","dependencies": {"progress": "^2.0.0","tar": "^6.2.1"  }}END)"

Here is the expected output:

{"name": "hello","dependencies": {"progress": "","tar": ""  }}

I have tried but not work:

# output="$(jq ".dependencies =(.dependencies | keys)" <<< "$json_string")"# echo "output is: $output"output is: {"name": "hello","dependencies": ["progress","tar"  ]}

It only converts the object to an array, but I want it still as object and only clear all values inside all keys.

What's wrong in my jq command and how to fix?


Viewing all articles
Browse latest Browse all 657

Trending Articles



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