Get formatted data in shell script which is read from file containing JSON data -
Write a shell script to get a list of names, current and latest available versions automatically from raw JSN data.
I am trying to format the JSON data stored in the file using the shell script. I tried to use the command line JSON Porter.
I have to format JSON data in script. There are advanced options available in JQ for their same choice. I am unable to use it properly.
Example: The following JSON file is
{"endpoint": {"name": "test-plugin", "version" "," dependency ": {" Plugin1 ": {" main ": {" name ":" plugin1name "," description ":" dummy text "}," pkgMeta ": {" name ":" plugin1name "," version ":" 0.0.1 "} , "Dependencies": {}, "version": ["0.0.5", "0.0.4", "0.0.3", "0.0.2" "" "", "Update": {"latest": "Name": "plugin2": {"main": {"name": "plugin2name", "description": "dummy text"}, "pkgmata": {"name": "plugin name 2" , "Version": "0.1.1"}, "dependency": {}, "version": ["0.1.5", "0.1.4", "0.1.3", "0.1.2", "0.1 .1 "]," update ": {" latest ":" 0.1.5 "}}}} to get results in the format In the words
[{name: "plugin1name", c_version: "0.0.1", n_version: "0.0.5"}, {name: "plugin2name", c_version: "0.1.1 What is a suggestion?
Your Jason file is not valid: .dependencies.pkgMeta.version . After fixing your JSON file, try this command:
jq '. Dependence | To_entries | | Map (.value | {name: .main.name, c_version: .pkgMeta.version, n_version: .update.latest}) 'input.json
The result is:
[{"name": "plugin1name", "c_version": "0.0.1", "n_version": "0.0.5"}, {"name": "plugin2name", "C_version": "0.1.1", "n_version": "0.1.5"}]
Comments
Post a Comment