This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding a new JSON Key to a Response

I'm modelling a REST service where a GET request is sent wherethe final portion of the message URL represents a Customer identifier: "https://<host>/<myservice>/12329666906070300000000"

The service responds with JSON messagewhich starts with:

 

{
    "12329666906070300000000": {
.....

where the first key value is the Customer identifier from the original request. 
Is it possible for a C# script to change the value of the key string in the response message? When I examine the C# types I can see that the learned data has been mapped to a new C# type

 

      public Number12329666906070300000000Type Number12329666906070300000000 { get; set; }

but there is no way (That I can see) to create a new type based on Customer identifiers sent in new requests.

 

  • 0

    This is currently not possible in the REST virtual service as the assumption is that keys are fixed and what is changing are the values.

    Possible workaround is to use a virtual service of Binary type, which doesn't structure the payload, data are encoded as Base64 and you can do whatever you need with it. The disadvantage is that for other tasks working with Binary data is harder compared to a structured data.

    Here is an example how to read/write Base64 encoded data: https://community.softwaregrp.com/t5/Service-Virtualization-User/Scripting-How-to-Work-with-Binary-Payload/td-p/1635123

  • 0 in reply to 

    Thanks, Jakub.

    Just one thing further. In a binary service how do I capture the Customer Id portion of the request?

    "https://<host>/<myservice>/12329666906070300000000"

    I need to be able to get this value in the script. In a REST service I would use the UriPath portion of the Reuqest object:

    string[] uriPath = hpsv.Request.HTTPInputParameters.UriPath.Split('/');
    string customerId = uriPath[2];

    That's not available in the Binary message.

    Tony