Junction Networks

Junction Networks Web Services API

JSON Response Format

JSON (JavaScript Object Notation) is a lightweight data format based on the object notation of the JavaScript language. It does not require JavaScript to read or write; it is easy to parse by any language and libraries and tools exist in many languages to handle JSON.

JSON Format Overview

JSON is a very simple text format based on JavaScript's object notation. The notation contains these basic elements:

  • Objects. Objects begin and end with braces ({}}.
  • Object members. Members consist of strings and values, separated by colon (:). Members are separated by commas.
  • Arrays. Arrays begin and end with braces and contain values. Values are separated by commas.
  • Values. A value can be a string, a number, an object, an array, or the literals true, false, or null.
  • Strings. Strings are surrounded by double quotes and contain Unicode characters or common backslash escapes.
For a complete description of JSON and its many uses, we suggest a visit to Douglas Crockford's JSON.org

How to Request JSON Output

  • To return an API response in JSON format, send a parameter "Output" in the request with a value of "json".
  • Optionally, set the parameter "Callback" in the request to specify a callback function.

For example, a call to the Echo action returns this:

{
 "Response":{
  "Context":{
   "Action":{
    "IsCompleted":"true"
   },
   "Request":{
    "IsValid":"true",
    "DateTime":"2006-12-27T23:18:16-05:00",
    "Duration":"1",
    "Parameters":{
     "Parameter":[
      {
       "Name":"Action",
       "Value":"Echo"
      },
      {
       "Name":"Output",
       "Value":"json"
      },
      {
       "Name":"TestName",
       "Value":"TestValue"
      }
     ]
    }
   },
   "Session":{
    "IsEstablished":"false"
   }
  },
  "Result":{
   "Echo":{
    
   }
  }
 }
}
          
You can see an example response here.

Callback Function

The Callback parameter (Callback=function) wraps the JSON output text in parentheses and a function name of your choosing.

Callback function names may only use upper and lowercase alphabetic characters (A-Z, a-z), numbers (0-9), the period (.), the underscore (_), and brackets ([ and ]). Brackets must be URL-encoded.

Results wrapped in callbacks look like this: ws_results( ...json output... );

Because JSON output is native JavaScript, you do not have to parse or evaluate the returned object in your callback function. You can immediately access the elements inside it, just as if you had passed an object reference to your ws_result function.

Callbacks are particularly useful for use with web service requests in client-side JavaScript. Normally web service requests using the XMLHttpRequest object run afoul of browser security restrictions that prevent files from being loaded across domains. This restriction requires you to proxy your requests on the server side or use server rewrites to trick the browser into thinking the web service data is coming from the same site as your web content.

Using JSON and callbacks, you can place the Junction Networks Service request inside a <script> tag, and operate on the results with a function elsewhere in the JavaScript code on the page. Using this mechanism, the JSON output from the Junction Neworks Web Services request is loaded when the enclosing web page is loaded. No proxy or server trickery is required.

A simple working example is Click to Call.