Working with Web Services > Making JSON requests

Making JSON requests

Each JSON (JavaScript Object Notation) request must contain certain information in order for Web Services to accept it. Making a JSON call is almost the same as making a REST call.

You must provide an appropriate endpoint for the request. For details, see Service endpoints.

You may want to include a custom header in order to avoid passing potentially sensitive information through the URL or that may show up in logs. For information on what can be included, see Custom HTTP headers.

You can include four additional parameters in a JSON call:

json - If set to "true" it returns the response in a JSON format.
prettyprint - If set to "true" it indents and formats the response for easy readability. This should only be used for testing purposes.
callback - This is used for cross-domain calls. It is the JavaScript method to pass the results into.
jsonPOST - Use this parameter for cross-domain calls to allow posting the JSON request using a GET call.

JSON requests are almost always HTTP GET calls. Where a REST call requires POST of XML (such as with the saveMyList operation) the system now allows a GET when you use the jsonPOST parameter containing the escaped post data. If you do a POST with the json parameter enabled, the system attempts to unmarshal the data as JSON or XML depending on the content-type.

In a response, all inner-elements and attributes of an element are treated as variables in the current variable.

For example, if the response normally returns XML like the following:

<parentElement xmlns="some:URI">

     <child1 att="First">

          <subchild1>Content</subchild1>

     </child1>

</parentElement>

Then, the JSON response format would be the following:

{

     "child1" : {

          "att" : "First",

          "subchild1" : "Content"

     }

}

Notice that the element and attribute are marshaled at the same level. Also, JSON does not serialize namespaces or root element names, so the parentElement and the URI are not returned.

JSON also requires some unique fault handling. For information, see Handling faults.

For more information about JSON, see http://www.json.org

Related topics 

 


© 2009-2012 SirsiDynix