Blog

Tutorial: Amazon.com Search API

Posted on

The JSON Object

Structure of a JSON Object

Figure 9
Structure of a JSON Object

JSON objects are made up of comma-separated “pairs” of values called associative arrays. Each value may itself be another array, or any one of several data types. A JSON object may contain several arrays nested within a main array as shown in the Figure 9 above.

Now that we have used the “Style” and “text/javascript” parameters to tell the Amazon Web Service to transform the XML output into JSON, we now need to process the information contained within the JSON object into a coherent HTML format. This is where the callback function comes into play. As previously mentioned, argument reflection enables any request parameter to be passed back with the response, regardless of whether it has an immediate significance to the Amazon Web Service. We can use the argument reflection functionality to make the XSL stylesheet output the JSON object response as a function call by including a “CallBack” parameter.

request += '&CallBack=amzJSONCallback';

In the XSL stylesheet, the function call to the callback parameter becomes the top element containing all the other JSON value “pairs”. See Figure 9. The JSON object is wrapped within the amzJSONCallback function argument.