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

jq command to iterate on JSON array with values having space

$
0
0

Input filename is project.json, and its content is:

{"package": [    {"path": "src","default": true    }  ],"name": "Sample","replacements": [    {"filename": "/src/main/CO_Config.xml","stringToReplace": "COMPANYUSERNAME","replaceWith": "COMPANYUSERNAME"    },    {"filename": "/src/main/CO Target System.xml","stringToReplace": "ENDPOINT","replaceWith": "ENDPOINT"    }  ],"namespace": "","sourceApiVersion": "61.0"}

My script below is reading JSON array 'replacements' and tries to replace strings on mentioned filename:

filename="project.json"if [[ ! -f "$filename" || ! -s "$filename" ]]; then return 1;fifor item in $(cat $filename | jq -c ".replacements[]" ); do    echo $item    # USE ITEM IN BELOW CODE    # replaceWithEnv=$(echo $item | jq -r ".replaceWithEnv\"")done

The output I get trims the spaces in "/src/main/CO Target System.xml":

    {"filename":"/src/main/CO_Config.xml","stringToReplace":"COMPANYUSERNAME","replaceWith":"COMPANYUSERNAME"}{"filename":"/src/main/COTargetSystem.xml","stringToReplace":"ENDPOINT","replaceWith":"ENDPOINT"}

Viewing all articles
Browse latest Browse all 543

Trending Articles



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