If I have a file with such content:
{"id":"doi-platelemetry-doi/doiplatelemetry","name":"doi/doiplatelemetry","location":"doi/doiplatelemetry/2.0.0/doiplatelemetry:2.0.0_49","component":"doi","tag":"2.0.0_49"},{"id":"doi-maintenance-service-doi/maintenance-service","name":"doi/maintenance-service","location":"doi/1.0.0/maintenance-service:1.0.0.681","component":"doi","tag":"1.0.0.681"}
How do we replace all / with - only in the value of location field? Meaning, after the replacement, the file content should be:
{"id":"doi-platelemetry-doi/doiplatelemetry","name":"doi/doiplatelemetry","location":"doi-doiplatelemetry-2.0.0-doiplatelemetry:2.0.0_49","component":"doi","tag":"2.0.0_49"},{"id":"doi-maintenance-service-doi/maintenance-service","name":"doi/maintenance-service","location":"doi-1.0.0-maintenance-service:1.0.0.681","component":"doi","tag":"1.0.0.681"}
This can be very easily achieved using jq but I am looking for a solution that works even when tools like jq are not available.
jqto properly manipulate JSON.jq. Was just thinking if we can achieve the same without extra tools. What I had pasted in the question was just a small part of the entire document thinking there must be solution withoutjq. On my original json document, this works perfectly fine:cat images.json | jq '.payload[].location |= "gsub("/";"-")' > images.json_modifiedjqis the right tool for the job. Anything you try withoutjqis going to be prone to errors.