IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
  • 1.  How to force an JSON object to display as an array

    Posted 01/27/15 03:55 AM

    I am working to convert some xml to json .EX:For the below

    John Doe Anna Smith Peter Jones

    I convert this XMl by converting to document and then to JSON

    I get this - an array of items in json (which is what I need):

    {“employees”:{“employee”:[{“firstName”:“John”,“lastName”:“Doe”},{“firstName”:“Anna”,“lastName”:“Smith”},{“firstName”:“Peter”,“lastName”:“Jones”}]}}

    But when there is only one it quite understandably converts like this (not an array):

    {“employees”:{“employee”:{“firstName”:“John”,“lastName”:“Doe”}}}

    My app developer who is reading this needs theJSON to return an array of items regardless or whether there is one or more.

    Is there a way of tricking it into thinking it’s an array or can someone suggest another way of doing this?


    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: How to force an JSON object to display as an array

    Posted 01/27/15 04:30 AM

    If pub.json:documentToJSONString gets a document with a list as element it generates an array, even if there is ony one element in it. Your problem probably is in the transformation to the document from the xml. Please have a look into the generated document using debugger, I assume you won’t have a list there if only one element is present. The fields arrays and makeArrays of pub.xml:xmlNodeToDocument allow for explicit control where to generate arrays.


    #webMethods
    #Integration-Server-and-ESB


  • 3.  RE: How to force an JSON object to display as an array

    Posted 01/27/15 04:43 AM

    Hello,

    Try out as suggestd below:

    get xmlf file
    pub.xml:xmlStringToXMLNode
    pub.xml:xmlNodeToDocument – initialise makeArrays=true
    pub.json:documentToJSONString

    Also test the code with makeArrays=false (You must set makeArrays to false when using documentTypeName to define the structure of an element. Otherwise, an exception will be thrown at run time.)


    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: How to force an JSON object to display as an array

    Posted 01/27/15 04:45 AM

    Hello,

    Try out as suggestd below:

    get xmlf file
    pub.xml:xmlStringToXMLNode
    pub.xml:xmlNodeToDocument -- initialise makeArrays=true
    pub.json:documentToJSONString

    Also test the code with makeArrays=false (You must set makeArrays to false when using documentTypeName to define the structure of an element. Otherwise, an exception will be thrown at run time.)


    #webMethods
    #Integration-Server-and-ESB