Appendix : Legacy Presto components : Mashables and Mashups : Mashups in EMML : Advanced Mashup Techniques : Handling JSON Responses or Inputs
Handling JSON Responses or Inputs
 
Convert JSON to XML
Post JSON to a Web Service Using <directinvoke>
Accept JSON as Input and Modify with <script>
Some web services return complex results in the JavaScript Object Notation (JSON) format. Some may also expect complex input parameters in the JSON format. There are two possible solutions to work with JSON data in mashups or macros:
*Pass or receive JSON data as strings and convert the JSON string to an XML document. Once converted to XML, you can use any EMML statements to work with the data.
The conversion from JSON to XML can fail, however, due to discrepancies between the valid syntax of each. Some common problem areas include valid names in JSON that are not valid names in XML and arrays, which JSON supports but XML does not.
See Convert JSON to XML for an example of this solution.
*Work with JSON data as an object with limitations to what EMML statements work with the data.
Input parameters, variables or the output parameter for a mashup or macro can have a datatype of document and a subtype of JSON, such as:
<input name="jsonInput" type="document" subtype="json"/>

<variable name="jsonVar" type="document" subtype="json"/>

<output name="jsonResult" type="document" subtype="json"/>
Parameters or variables with a JSON subtype, can be used directly only in these two EMML statements:
*<directinvoke>: as the request body to send to a web service, when the method is POST, or as the outputvariable to receive the response of the invocation. See Post JSON to a Web Service Using <directinvoke> for an example.
*<script>: as an input variable or the output of the script, with JavaScript as the scripting language.
With <script>, you can directly manipulate the JSON object using JavaScript methods. See Accept JSON as Input and Modify with <script> for an example.
Copyright © 2013-2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback