JSONP support in the JSON domain
JSONP (JavaScript Object Notation with Padding) is an extension of the JavaScript Object Notation (JSON) format.
IBM® App Connect Enterprise provides support for JSONP services. A JSONP service, or Remote JSON Service, is a web service that returns JSON data padded with a user-defined JavaScript function call. The JSONP response message can be interpreted as an executable script, so this functionality can be used to create cross-domain function calls.
http://brokerhost:7080/flowUrlPathSuffix?jsonp=scriptFn
- jsonp tells the JSONP service that any response from the URL must be returned as a JSONP message
- scriptFn is the name of a client-side executable function
scriptFn(response)
The JSON message tree provides a top level Padding
element,
into which the JSON parser places the name of the client-side JSONP
function. Similarly, the JSON serializer pads a JSON message if the
top-level element Padding
is present in the tree.
For more information about JSON, see JSON parser and domain.
For information about how to use IBM App Connect Enterprise to provide a JSONP service, see Providing a JSONP service.
For information about how to use IBM App Connect Enterprise to consume a JSONP service response, see Consuming a JSONP service response.
Example JSONP message
The following example shows a simple JSONP message:
scriptFn (
{
"name" : "John Doe",
"age" : -1.0,
"known" : false,
"address" : { "street" : null,
"city" : "unknown" },
"belongings" : ["item1", "item2", "item3"]
}
)
This JSONP input produces the following integration node logical message tree:
(0x01000000:Object):JSON = ( ['json' : 0xd55fc8]
(0x03000000:NameValue):Padding = 'scriptFn' (CHARACTER)
(0x01000000:Object ):Data = (
(0x03000000:NameValue):name = 'John Doe' (CHARACTER)
(0x03000000:NameValue):age = -1E+0 (FLOAT)
(0x03000000:NameValue):known = FALSE (BOOLEAN)
(0x01000000:Object ):address = (
(0x03000000:NameValue):street = NULL
(0x03000000:NameValue):city = 'unknown' (CHARACTER)
)
(0x01001000:Array ):belongings = (
(0x03000000:NameValue):Item = 'item1' (CHARACTER)
(0x03000000:NameValue):Item = 'item2' (CHARACTER)
(0x03000000:NameValue):Item = 'item3' (CHARACTER)
)
)
)