bash - How to set a property of a json file and replace in one command using jq -
this question has answer here:
how update single value in json document using jq? doesn't have answer question.
- read json file.
- update value.
- replace file.
expecting one inline command using jq
assume have following json file.
{ "name": "app", "value": "one", ... }
i want update value field "two". resulting json file should like
{ "name": "app", "value": "two", ... }
what simplest bash command , windows bat command this.
here demonstration of solution uses sponge
bash-3.2$ cat data.json { "name": "app", "value": "one" } bash-3.2$ jq -m '.value="two"' < data.json | sponge data.json bash-3.2$ cat data.json { "name": "app", "value": "two" }
Comments
Post a Comment