Topic
  • 6 replies
  • Latest Post - ‏2018-09-12T15:18:53Z by HermannSW
Gunjan_05
Gunjan_05
42 Posts

Pinned topic Query

‏2018-05-18T10:48:29Z |

Hi,

I have a query related to xml and json.

i am using existing MPGW which converts XML -->JSONX --> JSON.

Currently now i am getting XML and one of the node contains json message.

Example:

<data>
<field1>Test1</field1>
<field2>{"a":{"b":"c","d":"e"}}</field2>
</data>

When Input contains all fields as XML/String, we are successfully convert to jsonx.

How to convert inside field2 element in jsonx. (jsontojsonx using XSLT).

We have any function which convert JSON to JSONX.

** We have jsonxtojson as last proceesioing action mpgw and its existing framework.

 

 

Updated on 2018-05-19T06:26:04Z at 2018-05-19T06:26:04Z by Gunjan_05
  • HermannSW
    HermannSW
    8074 Posts
    ACCEPTED ANSWER

    Re: JSON in XML

    ‏2018-05-22T10:38:17Z  
    • Gunjan_05
    • ‏2018-05-18T12:10:22Z

    This is also the good option but we have manage one more service :)

    You can go for first option and use dp:url-open to send the JSON string against a http://127.0.0.1:somePort service with request type JSON that just returns the generated JSONX.

     

    But we dont have any extension function which convert JSON to JSONX

    But we dont have any extension function which convert JSON to JSONX
    >
    correct.

  • HermannSW
    HermannSW
    8074 Posts

    Re: JSON in XML

    ‏2018-05-18T11:58:33Z  

    Hi,

    there is no function you can call to convert JSON to JSONX.

    The conversion is done by DataPower firmware:

    • service request type JSON, you can find JSONX in context __JSONASJSONX
    • convert-http(JSON) action

    You can extract the JSON (string) from the XML, store into a context, and have a later convert-http(JSON) action with that context as input context do the JSONX conversion for you. If further processing is neeed, you need to have another stylesheet xform action doing that.

    This solution has minimal latency overhead.

    You can go for first option and use dp:url-open to send the JSON string against a http://127.0.0.1:somePort service with request type JSON that just returns the generated JSONX.

    Hermann.

    Updated on 2018-05-18T12:00:14Z at 2018-05-18T12:00:14Z by HermannSW
  • Gunjan_05
    Gunjan_05
    42 Posts

    Re: JSON in XML

    ‏2018-05-18T12:10:22Z  

    This is also the good option but we have manage one more service :)

    You can go for first option and use dp:url-open to send the JSON string against a http://127.0.0.1:somePort service with request type JSON that just returns the generated JSONX.

     

    But we dont have any extension function which convert JSON to JSONX

  • HermannSW
    HermannSW
    8074 Posts

    Re: JSON in XML

    ‏2018-05-22T10:38:17Z  
    • Gunjan_05
    • ‏2018-05-18T12:10:22Z

    This is also the good option but we have manage one more service :)

    You can go for first option and use dp:url-open to send the JSON string against a http://127.0.0.1:somePort service with request type JSON that just returns the generated JSONX.

     

    But we dont have any extension function which convert JSON to JSONX

    But we dont have any extension function which convert JSON to JSONX
    >
    correct.

  • HermannSW
    HermannSW
    8074 Posts

    Re: JSON in XML

    ‏2018-09-12T15:00:38Z  
    • HermannSW
    • ‏2018-05-22T10:38:17Z

    But we dont have any extension function which convert JSON to JSONX
    >
    correct.

    I thought again on this and created a blog postig on GatewayScript JSON2JSONX.js :
    https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/GatewayScript_JSON2JSONX_js_converts_JSON_to_JSONX_XML

    You can even do what you initially requested in XSLT, by calling out to GatewayScript:
    https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.6.0/com.ibm.dp.doc/gatewayscript_metadatafunction.html
     

    select="dp:gatewayscript('https://stamm-wilbrandt.de/en/blog/JSON2JSONX.js', /data/field2/text())"
    

     

    Hermann.

    Updated on 2018-09-12T15:03:13Z at 2018-09-12T15:03:13Z by HermannSW
  • fmoraes
    fmoraes
    30 Posts

    Re: JSON in XML

    ‏2018-09-12T15:14:54Z  
    • HermannSW
    • ‏2018-05-22T10:38:17Z

    But we dont have any extension function which convert JSON to JSONX
    >
    correct.

    Actually, we do now have extension functions in 7.7.1.2 and beyond that do JSON to JSONx conversion.

     

    https://www.ibm.com/support/knowledgecenter/en/SS9H2Y_7.7.0/com.ibm.dp.doc/binaryNodeToJSONx_metadatafunction.html

    https://www.ibm.com/support/knowledgecenter/en/SS9H2Y_7.7.0/com.ibm.dp.doc/stringToJSONx_metadatafunction.html

  • HermannSW
    HermannSW
    8074 Posts

    Re: JSON in XML

    ‏2018-09-12T15:18:53Z  
    • fmoraes
    • ‏2018-09-12T15:14:54Z

    Oops, I should get more knowledgeable on new contents of Continuous Delivery branch ... ;-)

    Hermann.