How to stub a JSON response

Not applicable

A simple question I hope; I am trying to implement a simple stub where I hard-code a response via an assign policy.

My policy looks like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="TestStub2"> <DisplayName>TestStub2</DisplayName> <FaultRules/> <Properties/> <Set> <Headers/> <QueryParams/> <FormParams/> <Payload>

{"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"} ] } }} </Payload>

<!-- <Verb>GET</Verb> --> <Path/> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>

I am facing two issues:

  1. In the response all curly braces '{}' inside the array delimited by square brackets '[]' are removed, apart from the first one
  2. In the response the first value 'menu' is dropped

Response looks like:

{ "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()", "Open", "onclick": "OpenDoc()", "Close", "onclick": "CloseDoc()" ] } }}

Is an assign the way to do what I am trying to do, and if yes, do I need to escape the hard-coded response?

thanks

jim

Solved Solved
0 1 1,662
1 ACCEPTED SOLUTION

Not applicable

Answer my own question: precede all { braces with backslash \\ so that they are not treated as variables. Hope this is useful for others!

View solution in original post

1 REPLY 1

Not applicable

Answer my own question: precede all { braces with backslash \\ so that they are not treated as variables. Hope this is useful for others!