2

When I try to perform the cURL request here, Windows 7 (x64) returns an output with no line breaks:

C:\Users\kiwi>curl http://www.documentcloud.org/api/search.json?q=group:nytimes

{"total":2821,"page":1,"per_page":10,"q":"group:nytimes","documents":[{"id":"862
75-isn-10015-abd-al-rahim-al-nashiri-jtf-gtmo","title":"ISN 10015 - Abd al Rahim
 al Nashiri - JTF-GTMO Detainee Assessment","access":"public","pages":15,"descri
ption":null,"source":null,"created_at":"Sun, 24 Apr 2011 15:50:19 +0000","update
d_at":"Mon, 25 Apr 2011 17:11:41 +0000","canonical_url":"http://www.documentclou
d.org/documents/86275-isn-10015-abd-al-rahim-al-nashiri-jtf-gtmo.html","resource
s":{"pdf":"http://s3.documentcloud.org/documents/86275/isn-10015-abd-al-rahim-al
-nashiri-jtf-gtmo.pdf","text":"http://s3.documentcloud.org/documents/86275/isn-1
0015-abd-al-rahim-al-nashiri-jtf-gtmo.txt","thumbnail":"http://s3.documentcloud.
org/documents/86275/pages/isn-10015-abd-al-rahim-al-nashiri-jtf-gtmo-p1-thumbnai
l.gif","search":"http://www.documentcloud.org/documents/86275/search.json?q={que
ry}","page":{"text":"http://www.documentcloud.org/documents/86275/pages/isn-1001
5-abd-al-rahim-al-nashiri-jtf-gtmo-p{page}.txt","image":"http://s3.documentcloud
.org/documents/86275/pages/isn-10015-abd-al-rahim-al-nashiri-jtf-gtmo-p{page}-{s
ize}.gif"}}},{"id":"86274-isn-10020-majid-khan-jtf-gtmo-detainee-assessment","ti
tle":"ISN 10020 - Majid Khan - JTF-GTMO Detainee Assessment","access":"public","
pages":12,"description":null,"source":null,"created_at":"Sun, 24 Apr 2011 15:50:
18 +0000","updated_at":"Mon, 25 Apr 2011 17:10:01 +0000","canonical_url":"http:/
/www.documentcloud.org/documents/86274-isn-10020-majid-khan-jtf-gtmo-detainee-as
sessment.html","resources":{"pdf":"http://s3.documentcloud.org/documents/86274/i
sn-10020-majid-khan-jtf-gtmo-detainee-assessment.pdf" ...

This may be the default behaviour, but is there anything I can do to get some readable JSON output when using cURL on Windows?

1

Not exactly, but here's a Python script that improves on that.

import urllib2
import simplejson
import pprint

URL = "http://www.documentcloud.org/api/search.json?q=group:nytimes"

def showfeed(argv):
    argv[1] if len(argv) > 1 else URL
    fo = urllib2.urlopen(URL)
    obj = simplejson.loads(fo.read())
    pprint.pprint(obj)

if __name__ == "__main__":
    import sys
    showfeed(sys.argv)
| improve this answer | |
  • I’ll definitely keep this in mind. It is probably possible to rework it to format JSON output from cURL inside the terminal, but that is most likely outside my own current ability. I’ll see what other users may know. But nevertheless, even outside the scope of the question, as someone who focuses his programming on Python, this is very valuable. – Kiwi Apr 25 '11 at 19:08
  • The terminal won't help you. You need a program to format it. I don't think curl does formatting, either. On a posix platform this would usually be done with tools in a pipeline. – Keith Apr 25 '11 at 19:25
1

Its an old question but I want to answer in total's simple context.

  1. Install Node.Js (Optional) - If you do not have Node js then download the LTS Version of Node JS (you can even install latest if you want)
  2. After Installation (or if you already have node js install then just for confirmation type node -v and npm -v.
  3. Both should return a proper version numbers as shown below

Snapshot of Node js and Npm Version Numbers

  1. Once you are done with installation confirmation then go ahead and install global version (using -g) flag of jsontool lib on node. npm install -g jsontool

json tool npm installation

  1. Once you are done with the installation in previous step then simply use the pipe | json in last line of curl request.
  2. Output without json pipe without json pipe
  3. Output with json pipe output pretty with json pipe
| improve this answer | |
0

Check out HTTPie, it's like cURL but a lot more human friendly, meaning that it will format json response accordingly and the like:

http://httpie.org/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.