Parse json in command line terminal

Tags: json terminal jq

I want to use jq for processing my json file in terminal. I am trying this command:

cat json.txt | jq 'name'

it's showing me

-bash: /usr/bin/jq: cannot execute binary file

Expected result:


where json.txt is indeed a valid json file. I tried to check whether jq is installed correctly. Here's what I am getting:

 brew install jq

it's showing me:

Warning: jq-1.3 already installed

I am using mac. Anybody has any idea? The json.txt file is:

    "name": "Google",
                    "street": "1600 Amphitheatre Parkway",
                    "city": "Mountain View",
                    "state": "California",
                    "country": "US"
                            "name": "Michael",
                            "division": "Engineering"
                            "name": "Laura",
                            "division": "HR"
                            "name": "Elise",
                            "division": "Marketing"


Regarding getting your expected result, the filter you want to use is:


Note the .. You want to get the value of the name property.

As for the error, I don't know what your environment is but it seems to indicate that you've installed the wrong version of jq that isn't compatible with your OS. Look for a good tutorial on how to get it installed on your machine.

This video can help you solving your question :)
By: admin