change json file by bash script

前端 未结 5 1098
醉话见心
醉话见心 2020-12-12 12:20

I need your help to solve the following problem: I have a JSON file that looks like this:

{
  \"key1\": \"value1\",
  \"key2\": \"value2\",
  \"key3\": \"val         


        
5条回答
  •  攒了一身酷
    2020-12-12 12:55

    Not the answer for everyone, but if you already happen to have NodeJs installed in your system, you can use it to easily manipulate JSON.

    eg:

    #!/usr/bin/env bash
    jsonFile=$1;
    
    node > out_${jsonFile} <

    Heck, if you only need to do JSON manipulation and you have node (ie: You don't really need any other bash functionality) you could directly write a script using node as the interpreter:

    #! /usr/bin/env node
    var data = require('./'+ process.argv[2]);
    /*manipulate*/
    console.log(JSON.stringify(data));
    

提交回复
热议问题