IDigBio API v1 Examples: Difference between revisions

convert to sections so they show up in ToC →‎Viewing JSON Output
(add simplejson)
(convert to sections so they show up in ToC →‎Viewing JSON Output)
Line 44: Line 44:
It may be useful to format the output of the JSON document using a "pretty printing" feature of some kind. This will make it more readable by humans and also allow it to be more easily filtered using tools such as <code>grep</code>. Two common tools for this available on Unix/Linux are python's json.tool or the json_pp command-line Perl script (JSON::PP). These tools can receive input from a pipe in the normal Unix fashion to chain multiple commands together.
It may be useful to format the output of the JSON document using a "pretty printing" feature of some kind. This will make it more readable by humans and also allow it to be more easily filtered using tools such as <code>grep</code>. Two common tools for this available on Unix/Linux are python's json.tool or the json_pp command-line Perl script (JSON::PP). These tools can receive input from a pipe in the normal Unix fashion to chain multiple commands together.


'''json.tool Example'''
==== json.tool ====
<pre>
<pre>
$ curl -s http://api.idigbio.org/ | python -m json.tool
$ curl -s http://api.idigbio.org/ | python -m json.tool
Line 54: Line 54:
</pre>
</pre>


'''json_pp Example'''
==== json_pp ====
<pre>
<pre>
$ curl -s http://api.idigbio.org/ | json_pp
$ curl -s http://api.idigbio.org/ | json_pp
Line 66: Line 66:
For best viewing of JSON results in a browser, one may wish to use the JSONView Extension for Chrome and Firefox.
For best viewing of JSON results in a browser, one may wish to use the JSONView Extension for Chrome and Firefox.


'''JSONView Browser Extension Example'''
==== JSONView Browser Extension ====


[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]]
[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]]


'''simplejson Example'''
==== simplejson ====


Some older systems may not include json_pp or python's json.tool.  The python simplejson package may solve this problem. Older versions of python also may require a more complicated syntax to invoke the module from the command line.
Some older systems may not include json_pp or python's json.tool.  The python simplejson package may solve this problem. Older versions of python also may require a more complicated syntax to invoke the module from the command line.
1,554

edits