none
How to handle multiple Json Responses RRS feed

  • Question

  • Hi,

    I am calling a REST service using WCF-WebHTTP adapter. and the rest service returns different response formats for single and multiple records as mentioned below.


    Single:

    {
        "Link": [
            {
                "rel": "self",
                "href": "xxx",
                "name": "xxx"
            }        
        ],
        "Head_ID": "",
        "Customer_Language_ID": "0-L5KZ"    

    }

    Multiple:

    {
        "items": [
            {
                "Link": [
                    {
                        "rel": "self",
                        "href": "xxx",
                        "name": "xxx"
                    }                
                ],
                "Head_ID": "",
                "Customer_Language_ID": ""            
            },
            {
                "Link": [
                    {
                        "rel": "self",
                        "href": "xxx",
                        "name": "xxx"
                    }                
                ],
                "Head_ID": "",
                "Customer_Language_ID": ""            
            }
            ]
            "Link": [
                    {
                        "rel": "self",
                        "href": "xxx",
                        "name": "xxx"
                    }                
                ]
            ]
     }

    I am using pipeline to decode the message, this is working for any one format at a time. not both the formats. Any suggestions would be a great help. 

    Thanks In advance.

    Monday, November 4, 2019 12:27 PM

Answers

  • There are two options

    • Create a schema that has a choice no, for either structure.
    • Use a component like the BRE Pipeline to inspect the payload and execute the JSON Decoder with the correct settings.


    • Marked as answer by A.Shannu Tuesday, November 5, 2019 6:46 AM
    • Edited by Colin Dijkgraaf Tuesday, November 5, 2019 8:50 PM
    Monday, November 4, 2019 9:23 PM

All replies

  • There are two options

    • Create a schema that has a choice no, for either structure.
    • Use a component like the BRE Pipeline to inspect the payload and execute the JSON Decoder with the correct settings.


    • Marked as answer by A.Shannu Tuesday, November 5, 2019 6:46 AM
    • Edited by Colin Dijkgraaf Tuesday, November 5, 2019 8:50 PM
    Monday, November 4, 2019 9:23 PM
  • Thanks for the reply.

    I have already tried the first option. it is working.

    • Marked as answer by A.Shannu Tuesday, November 5, 2019 6:48 AM
    • Unmarked as answer by A.Shannu Tuesday, November 5, 2019 7:17 AM
    Tuesday, November 5, 2019 6:47 AM
  • Hi Shannu - I have this same exact scenario. My response will be coming with always Multiple records. When I am trying to create JSON schema wizard for this multiple records, I am receiving following error :

    There was an error while parsing JSON 

    {
        "items": [
            {
                "Link": [
                    {
                        "rel": "self",
                        "href": "xxx",
                        "name": "xxx"
                    }                
                ],
                "Head_ID": "",
                "Customer_Language_ID": ""            
            },
            {
                "Link": [
                    {
                        "rel": "self",
                        "href": "xxx",
                        "name": "xxx"
                    }                
                ],
                "Head_ID": "",
                "Customer_Language_ID": ""            
            }
            ]
            "Link": [
                    {
                        "rel": "self",
                        "href": "xxx",
                        "name": "xxx"
                    }                
                ]
            ]
     }

    How was you able to achieve this ? Can you please advise step by step ?


    RH



    • Edited by Dan2890 Friday, November 8, 2019 3:15 PM A
    Friday, November 8, 2019 3:11 PM