DataPower

DataPower

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.

 View Only
Expand all | Collapse all

Handling JSON payload with Unicode during JSONx conversion

  • 1.  Handling JSON payload with Unicode during JSONx conversion

    Posted Fri August 21, 2020 05:15 AM

    Currently using a MPGW service with request type "non-xml" and trying to convert JSON to JSONx (XML).

    Some JSON payloads with Unicode character are throwing error in DataPower with error message:

    "Invalid string syntax"

    Some other JSON payloads with Unicode are processed by JSON parser without any issue.

    Is there any way to parse all these JSON payloads successfully in DataPower?



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: Handling JSON payload with Unicode during JSONx conversion
    Best Answer

    Posted Fri August 21, 2020 05:16 AM

    In short answer, some of the Unicode characters are not valid XML characters after the JSONx conversion.

    For longer answer:

    According JSON spec the character encoding is a hexadecimal number:

    https://tools.ietf.org/html/rfc8259#section-7

    Certain Unicode character such as \u000a (Line Feed) is a XML character:

    Other Unicode characters such as \u000b (Line Tabulation) and \u0010 (Data Link Escape) is not:

    https://en.wikipedia.org/wiki/C0_and_C1_control_codes

    Example of common XML ASCII control characters are \u0009, \u000a and \u000d for XML 1.0:

    https://www.w3.org/TR/REC-xml/#charsets

    It is not possible for JSONx conversion to process JSON with string characters that are not valid XML characters.

    The reason is because after parsing JSON, there is no escaping anymore, and each JSON character is internally a parsed XML character.

    Changing the request type to "json" is not a valid solution either:

    The same JSON payload would also fail because request type JSON does implicit conversion of input to JSONX, which gets stored in __JSONASJSONX context.

    https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/request-type_webtokenservice.html

    To workaround this, it is necessary to use GatewayScript to process JSON that cannot be processed with JSONx because of the XML spec.



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: Handling JSON payload with Unicode during JSONx conversion
    Best Answer

    Posted Sat August 22, 2020 11:55 AM

    Some JSON payloads with Unicode character are throwing error in DataPower with error message:



    #DataPower
    #Support
    #SupportMigration


  • 4.  RE: Handling JSON payload with Unicode during JSONx conversion
    Best Answer

    Posted Sat August 22, 2020 05:04 PM

    Some JSON payloads with Unicode character are throwing error in DataPower with error message:



    #DataPower
    #Support
    #SupportMigration