Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Tony_Cunningham Frequent Contributor.
Frequent Contributor.

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.


2 Replies
Micro Focus Expert
Micro Focus Expert

Re: Adding a new JSON Key to a Response

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

Service Virtualization R&D
Tony_Cunningham Frequent Contributor.
Frequent Contributor.

Re: Adding a new JSON Key to a Response

Thanks, Jakub.

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


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.


The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.