1,554
edits
(add link to jsonview →JSONView Browser Extension) |
(clarify and reorg →Viewing JSON Output) |
||
Line 8: | Line 8: | ||
Javascript Object Notation ([http://en.wikipedia.org/wiki/JSON JSON]), is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. JSON has become a common format for interchanging data via APIs and especially modern Web Services. Effective use of the iDigBio API will require some understanding of JSON. | Javascript Object Notation ([http://en.wikipedia.org/wiki/JSON JSON]), is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. JSON has become a common format for interchanging data via APIs and especially modern Web Services. Effective use of the iDigBio API will require some understanding of JSON. | ||
Most of the examples provided here will be shown using the <code>curl</code> command-line tool. Here are some of the more commonly used curl options (for descriptions and additional usage information, see the curl man page): | Most of the examples provided here will be shown using the <code>curl</code> command-line tool. Here are some of the more commonly used curl options (for descriptions and additional usage information, see the curl man page): | ||
Line 30: | Line 22: | ||
</pre> | </pre> | ||
A short JSON document is returned by the API when calling the GET method (curl's default) against the base URL: | A short JSON document is returned by the API when calling the HTTP "GET" method (curl's default) against the base URL: | ||
<pre> | <pre> | ||
$ curl | $ curl http://api.idigbio.org/ | ||
{"v1":"http://api.idigbio.org/v1/","v0":"http://api.idigbio.org/v0/","check":"http://api.idigbio.org/check"} | {"v1":"http://api.idigbio.org/v1/","v0":"http://api.idigbio.org/v0/","check":"http://api.idigbio.org/check"} | ||
</pre> | </pre> | ||
It may be useful to inspect the API's JSON document outputs 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 module or the json_pp command-line Perl script (JSON::PP). In typical Unix fashion, these tools can receive input from a pipe and be used to chain multiple commands together. | |||
There are also ways of viewing JSON inside of a web browser. | |||
==== JSONView Browser Extension ==== | |||
For best viewing of JSON results in a browser, one may wish to use the [http://jsonview.com/ JSONView Extension] which is available for Firefox and Chrome. | |||
Here is a screenshot of the output using the JSONView extension after requesting the same API base URL: | |||
[[File:JSONView_browser_extension_example.png|border|JSONView extension allows easier viewing in a web browser]] | |||
==== json.tool ==== | ==== json.tool ==== |
edits