Skip to content
Advertisement

How to read a property value of json file located local on Ubuntu Terminal

I have a json file like below:

{
  "result": {
    "covered_percent": 47.06
  }
}

and how can I read this value on Ubuntu Terminal.

Advertisement

Answer

You didn’t mention which version of ubuntu but as a 1 liner from the terminal this works for me (assumes json file is in same directory and called json_file.json)

python -c "import json;print json.loads(open('json_file.json', 'r').read())['result']['covered_percent']"
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement