App Connect

 View Only
Expand all | Collapse all

API Connect allowinj json strings with double quotes embedded inside.

  • 1.  API Connect allowinj json strings with double quotes embedded inside.

    Posted Wed August 03, 2022 09:05 AM
    Edited by Kristen Park Thu August 04, 2022 09:35 AM
    Hi ,

    We are using IBM API Connect 2018 in our environment. We are seeing some issues in PROD environment related to XML parse errors.
    The xml field causing this issue is initially inserted(in a json message into our DB).This DB insert has inserted some special characters and is causing XML parse errors.

    The json element is of type string with double quotes embedded in it.For example 

    "testField":"Theraband "BLUE" Resistance Band ,1 x metre "

    As per my understanding this is not a valid json string and should not be allowed. However looks like this was processed by API Connect and inserted into DB by subsequent IIB flows.

    Trying to understand why this is working in PROD. The same message were rejected when I was trying out test API on my postman .

    {
    "httpCode": "400",
    "httpMessage": "Bad Request",
    "moreInformation": "The body of the request, which was expected to be JSON, was invalid, and could not be decoded. The object syntax was invalid."
    }

    Thanks,
    Ashish Thakur

    ------------------------------
    Ashish Thakur
    ------------------------------


  • 2.  RE: API Connect allowinj json strings with double quotes embedded inside.
    Best Answer

    Posted Thu August 25, 2022 02:29 PM

    You are correct, this is not valid JSON and you should work with the developers to correct the errant data.  JSON requires the inner quotes to be escaped.
    I can't speak to the APIC part, but for IIB, it can often tolerate bad input.  IIB will auto-escape the data.  This does not mean that you should rely on IIB to always behave this way.  It also depends a large part in how the data gets to IIB and what parsers are used.  For example, the DB does not have a JSON data type.  It will take any string or CLOB data.  Depending on how that is structured and gets set in the message will determine if IIB can handle it.  If you do something like:

    SET OutputRoot.JSON.Data.DBResponse.testField = THE(SELECT testField FROM myDatabase WHERE id=1);

    Then IIB will manage the inner quotes for you.

    Without details of the flow and data, I can't give a definitive answer for IIB or APIC.  You may need to engage Support for assistance.



    ------------------------------
    MATTHEW SEGALL
    ------------------------------