cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a dynamic value in json using blueprism

NavithaK
Level 3
Hi,

We have a JSON format which needs to be sent as a input payload. How can we assign values in the JSON dynamically? We have values in the different data items and these values need to be replaced in the JSON.

For example:
I have json data:
{
"name": "xyz",
"Type": "Input"
}
In this, I need to replace the value xyz with other value from the data item dynamically using blueprism.

Can anyone please help on this.

------------------------------
Navitha K
------------------------------
4 REPLIES 4

PeterLacken
Level 7
Hi,

I would try the Utility - JSON VBO and convert the JSON to a collection, do the updates on the collection, then convert back to JSON.

if it is something simpler then a string replace might be more suitable using a calc stage and Replace function.

peter

------------------------------
PeterLacken
Ren Røros Intelligent Automation
Peter.Lacken@rria.no
http://www.rria.no
------------------------------

GopalBhaire
Level 10


Hi Navitha

JSON is a string so you can directly use replace to replace the xyz with your new value.

Or you can extend the Utility - JSON VBO to convert the json string into a Dictionary and change the value, after which you can serialize and return the output.

Dim values = JsonConvert.DeserializeObject(json)
values(key) = newVal
op = JsonConvert.SerializeObject(values, Formatting.None)





------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

EmersonF
MVP
Today, i use the replace function, i write the default value, exemple "name": "%" and make Replace([DataJson];"%": [NewValue]) Or you can use regex expression for capture the value "XYZ" and make Replace([DataJson]; [CapturedValue];[NewValue])

------------------------------
Emerson Ferreira
Sr Business Analyst
Avanade Brasil
America/Recife
+5581988869544
If my answer helped you? Mark as useful!
------------------------------
Sr Cons at Avanade Brazil

ewilson
Staff
Staff
Are you working with the WebAPI service feature or a code stage? If you're using the WebAPI service feature to invoke a RESTful service you can select Template from the Request Body options and then add your JSON format as a template. Then you make the value portion of each element a parameter. Here's an example:

7209.png
7210.png
If you're doing this through a code stage/VBO, the answers provided by the other commenters should work well.

Cheers,

------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------