2

I'm getting a JSON based output when sending GET requests to an API online, using Cygwin. I know how to manage JSON files over PHP and JS, but in this I wish to keep using Cygwin.

Is there any way to "handle" those files, getting fields' value, etc? I know I can "create" something manually with sed, grep, awk and such - but I'm looking, first of all, for something which is "ready-to-use".

Example:

{
    "campaign": {
        "name": "my campaign",
        "id": 1434,
        "creatives": [
                {
                    "id": 4162,
                    "state": "active"
                }
            ],
}
}
rudolph9
  • 8,021
  • 9
  • 50
  • 80
Etay Liberman
  • 175
  • 1
  • 11
  • You'll have to use some sort of command line application. There are a lot of things out there that do this. You would have to use sed/awk if you want the solution to be written in pure bash, but there are a lot of perl/python/js scripts out there to do it. http://stackoverflow.com/questions/1955505/parsing-json-with-sed-and-awk – kelorek Aug 21 '13 at 15:04
  • http://kmkeen.com/jshon/ https://github.com/kristopolous/TickTick http://stackoverflow.com/questions/1955505/parsing-json-with-sed-and-awk http://stackoverflow.com/questions/3858671/unix-command-line-json-parser – x29a Aug 21 '13 at 15:06
  • if you're comfortable with awk, look for jsawk. Good luck. – shellter Aug 21 '13 at 15:32

2 Answers2

3

A great option is to use 'jq'. It is a command line JSON query tool. There is a source tarball available for Linux/Cygwin etc that you can build and use to query JSON directly as well as pipe it into other tools. https://stedolan.github.io/jq/download/

dragon788
  • 3,583
  • 1
  • 40
  • 49
0

I think you can start from something like this:

curl HOST:PORT/API | jq -r '.KEY'