Contributions
Re: Multiline string in readable format for mediatype application/json
Hirichie, I have saved the string array in a variable and joined using 'join' method [defjoin1 = separate.join()], but this way it is saving the variable as a groovy string(obviously) and when I extract it into an external file using 'write' method [inputFile.write(join1)], it is still the same groovy string and when I pass this external file as an attachment in to rest request with media type 'application/json', I get "unable to parse json" exception and that is same even if I save the variable as a property and call the property in the request, so I think what would resolve the problem is if I could extract the whole string as a json string and any help in achieving this would be hugely appreciated. Below is my groovy: def separate = [ '{', '"messageId" : "unigeID111",', ' "messageType" : "IA8",', '"message" :"<con:Control xmlns:con=\"http://www.abc/Trade/Common/ControlDocument\">', '<con:MetaData>', '<con:MessageId>WK033</con:MessageId>', </con:MetaData>', '<con:OperationRequest>', '<con:Parameters xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">', <con:Parameter Name=\"message\">', '<![CDATA[<IA8 xmlns=\"urn:publicid:-:EC:DGTAXUD:EMCS:PHASE4:IA8:V3.01\" xmlns:tms=\"urn:publicid:-:EC:DGTAXUD:CS:PHASE4:TMS:V3.01\">', '<Header>', '<tms:MessageSender>NA.X</tms:MessageSender>', '</Header>', '<Body>', '<SubmittedDraft>', '<Attributes>', '<SubmissionMessageType>1</SubmissionMessageType>', '</Attributes>', '</SubmittedDraft>', '</Body>', '</IA8>]]>', '</con:Parameter>', ' </con:Parameters>', '<con:ReturnData><con:Data Name=\"schema\"/></con:ReturnData>', '</con:OperationRequest></con:Control>"', '}' ] def join1 = separate.join() def fileName = "abc.txt" def inputFile = new File("/home/Desktop/"+fileName) inputFile.write(join1) Thanks Raj3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2KViews0likes0CommentsRe: Multiline string in readable format for mediatype application/json
Hirichie Appreciate the response, thanks for the line break correction, it was a typo and in my actual I used the right one which didn't work. Sorry for the confusion, I now understood the solution you provided, infact option 1 of externalising the data is what I am working upon as well, in groovy script step I have saved the whole string as multiple line array and parameterised the xml element contents and then using join() method made it into one line and saved in a different variable, now I want to write this variable value into an external file and in the request step, want to provide the request body this external file as an attachment. Which may work in my opinion as you also suggested. Wondering if you have any groovy script to write this groovy variable which holds my combined string into an external text file ?3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2KViews0likes2CommentsReadyAPI replaces '<' with '<' when using Test Case Property in Rest Request
I have a test case property which I want to use in my json body as a value, the value is of type 'xml' but when I use the test case property this way I get 'bad request' error as '<' is replaced with '<' Eg: My test case property value = <con:MetaData> Replaced with<con:MetaData>3 years agoPlace ReadyAPI QuestionsReadyAPI Questions317Views0likes1CommentRe: Multiline string in readable format for mediatype application/json
Heyrichie 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 request3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.1KViews0likes4CommentsMultiline 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>" }Solved3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.3KViews0likes6Comments