Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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)
share|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
add comment

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/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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