Webcams.travel - The Webcam Community - Home
Live   Popular   Featured   New   Map


Back to the API index page

Developer API - JSON(P) response format


JSON - JavaScript Object Notation - is a lightweight data-interchange format. It is easy for humans to read and write, it is easy for machines to parse and generate and it is based on a subset of the JavaScript Programming Language. Read more about JSON.

To set the response format to JSON, send the parameter format=json along with the method call.

Response structure

The JSON objects are a direct mapping of the XML block from the XML response format. Some examples will explain the mechanism.

First, the simple XML tag
<foo>bar</foo>
will be translated to
{
	"foo": "bar"
}
Each tag is a JSON object member
<webcam>
	<webcamid>1234</webcamid>
	<title>Foo</title>
	<owner>Bar</owner>
</webcam>
{
	"webcam": {
		"webcamid": "1234",
		"title": "Foo",
		"owner": "Bar"
	}
}
Repeated elements are translated to arrays
<webcamlist>
	<webcam>
		<webcamid>1234</webcamid>
		<title>Foo</title>
	</webcam>
	<webcam>
		<webcamid>5678</webcamid>
		<title>Bar</title>
	</webcam>
</webcamlist>
{
	"webcamlist": {
		"webcam": [
			{
				"webcamid": "1234",
				"title": "Foo"
			},
			{
				"webcamid": "5678",
				"title": "Bar"
			}
		]
	}
}

Responses

Successful responses contain the XML payload translated into JSON objects with the extra member "status". A successful call to wct.webcams.get_details would return this XML response:
<?xml version="1.0" encoding="utf-8"?>
<wct_response status="ok">
	<webcam>
		<webcamid>1234</webcamid>
		<title>Foo</title>
		<owner>Bar</owner>
	</webcam>
</wct_response>
The JSON equivalent would be
{
	"status": "ok",
	"webcam": {
		"webcamid": "1234",
		"title": "Foo",
		"owner": "Bar"
	}
}
If an error occurs, the XML response would be like this:
<?xml version="1.0" encoding="utf-8"?>
<wct_response status="fail">
	<error>
		<code>2</code>
		<description>Missing required parameter</description>
	</error>
</wct_response>
The JSON equivalent would be
{
	"status": "fail",
	"error": {
		"code": 2,
		"description": "Missing required parameter"
	}
}

Callback function / JSONP

By default the JSON response is not wrapped by a callback function. To define your own callback function name, add the parameter callback with the name of your callback function as value to the request.
[default]          -> {...}
callback=Foobar    -> Foobar({...});
The callback parameter will be ignored if it is empty or the response format is not json.


Back to the API index page
Webcam search