Forum Discussion

rajrao's avatar
rajrao
Occasional Contributor
3 years ago
Solved

Multiline string in readable format for mediatype application/json

Hi,

 

Our Rest API request has json body and one of the values is a  multiline String(XML), when I paste the json body in readyapi request editor and send, I get errors if the whole string is not in single line, for readability purpose am wondering if there is a way I could have this string value(which is a 100 tags XML) on multiple lines rather than having it in one huge single line ? 

 

My JSON request example below and the key 'message' has a value in 'xml' format and type 'string'. I have only pasted few lines below but my xml string is more than 100 tags. All those 100 tags need to be in one line for the validation to be successful but that is making the string unreadable, so wondering if there is a way I can have each tag in a separate line so that the request can be easily readable.

{
"messageId": "123456",
"source": "messageReceiver",
"message": "<con:Control xmlns:con=\"http://www.gov.com/taxation/InternationalTrade/Common/ControlDocument\">
<con:MetaData>
<con:MessageId>00001733</con:MessageId>
<con:Source>ABC</con:Source>
</con:MetaData>
<con:OperationRequest>
<con:Parameters xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<con:Parameter Name=\"ExciseRegistrationNumber\">00467015</con:Parameter>
<con:Parameter Name=\"message\">
<![CDATA[<IA815 xmlns=\"urn:publicid:-:EC:DGTAXUD:PHASE4:IA815:V3.01\" xmlns:tms=\"urn:publicid:-:EC:DGTAXUD:PHASE4:TMS:V3.01\">
<Header>
<tms:MessageSender>NDA.AB</tms:MessageSender>
<tms:MessageIdentifier>902M57S53x1</tms:MessageIdentifier>
</Header>
<Body>
<SubmittedDraftOfEAD>
<Attributes>
<SubmissionMessageType>1</SubmissionMessageType>
<DeferredSubmissionFlag>0</DeferredSubmissionFlag>
</Attributes>
</SubmittedDraftOfEAD>
</Body>
</IA815>]]>
</con:Parameter>
</con:Parameters>
<con:ReturnData><con:Data Name=\"schema\"/></con:ReturnData>
</con:OperationRequest></con:Control>"
}

  • Hey rajrao,

    I dont think there is. Ive come across this myself a while back and the problem was the endpoint's validation didnt like the split....it wasnt a ReadyAPI issue.

    Totally get what youre saying about the message pane window being tiny.....especially when exercising REST APIs (rather than say SOAP) where half the available screen is used up by the Request's API parms editable frame.

    When i had this issue i found 2 options (dunno if the other forum members have any better ideas?)

    You can either:

    1. Externalise your data in .csv's enabling you to edit payloads in Excel or whatever, OR
    2. There is a button with the alt-text help (immediately above the Smart Assertion button) "Toggles to tab based layout". This changes the view so rather than a vertical split in middle of screen splitting the request and response, it alters the view to show one in front of the other (extending the available screen space, doubling the visible horizontal width of the Request's payload input field.

    Those are the only 2 options i found that would help.

    Cheers,

    Rich

6 Replies

  • richie's avatar
    richie
    Community Hero
    Hey rajrao,

    I dont think there is. Ive come across this myself a while back and the problem was the endpoint's validation didnt like the split....it wasnt a ReadyAPI issue.

    Totally get what youre saying about the message pane window being tiny.....especially when exercising REST APIs (rather than say SOAP) where half the available screen is used up by the Request's API parms editable frame.

    When i had this issue i found 2 options (dunno if the other forum members have any better ideas?)

    You can either:

    1. Externalise your data in .csv's enabling you to edit payloads in Excel or whatever, OR
    2. There is a button with the alt-text help (immediately above the Smart Assertion button) "Toggles to tab based layout". This changes the view so rather than a vertical split in middle of screen splitting the request and response, it alters the view to show one in front of the other (extending the available screen space, doubling the visible horizontal width of the Request's payload input field.

    Those are the only 2 options i found that would help.

    Cheers,

    Rich
    • rajrao's avatar
      rajrao
      Occasional Contributor

      Hey richie 

      Thanks for the response, appreciate taking time to answer. Maybe I wasn't very clear in explaining what my problem was, apologies.

      My Rest API request hasn't got any parameters. It is a 'json body' with key-value pairs, and one of the key-value is an 'XML' of type 'STRING' and this string xml is very big and would like to have it spread across multiple lines rather than one line. If the whole string is not in one line then I get a json validation error and the line breaks like '/n' doesn't help.

      P.S: I have edited my original post now and also copied part of my request

       

      • richie's avatar
        richie
        Community Hero
        Hey rajrao,

        I did totally understand so i think we've both confused each other.

        I was providing workarounds in case there was no way around your schema validation!😁

        I did notice however that your newline break was incorrect. You tried '/n', right? Well in json a newline break is '\\n' instead.

        Try '\\n' instead. If that isnt allowed by the validation then youll have to go with a workaround.

        Cheers,

        Rich