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.

  1. read json file.
  2. update value.
  3. 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

Popular posts from this blog

minify - Minimizing css files -

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -