How to Add a variable to json config

hi All ,
i have config file which is json i need to add a key and value in such a way that a json has another json into it.
for eg:
{
“key”:“value”,
“key2”:“value2”,
“key3”:[
{
“inner1”:“v1”,
“inner2”:v2,
}
]
}
But when i am trying to store this and deserlize this json string i am getting an error so can anyone help me out to solve this problem

Hi @vishal_nachankar ,

Try this Text :

{
"key":"value",
"key2":"value2",
"key3":[
{
"inner1":"v1",
"inner2":"v2"
}
]
}

There was a Double Quote missing in v2. Maybe that was the reason.

are you looking for this target?

{
“key”:“value”,
“key2”:“value2”,
“key3”:[
{
“inner1”:“v1”,
“inner2”:“v2”
}
]
“key4”:[
{
“inner1”:“v1”,
“inner2”:“v2”
}
]
}

no i dont want the double quotes explictly for v2

also remove the comma from the last property

i dont want double quotes on v2

when v2 is a string the double quote is needed otherwise use a number for a dummy value

see i will be replacing the values after deserlizing the json.
so i need the final output if i try to access the key3 is
[
{
“inner1”:“v1”,
“inner2”:v2
}
]
and i will replace the v1 and v2 with my desired values and pass this whole string as a body to http request

Hello,

If v2 is a variable, replace that with {0} and while deserializing, use this:
String.Format( str_JsonString, VariableName)

Thanks!
Athira

can you share the example please

we would not recommend to do too much string tricks when working with JSON

1 Like

Suppose the JsonString is this:
{{
“key”:“value”,
“key2”:“value2”,
“key3”:[
{{
“inner1”:“{0}”,
“inner2”:“{1}”
}}
]
}}

Use Assign activity:
Str_JsonString= String.Format( str_JsonString, v1,v2)

So inner1 and inner2 will be replaced with v1 and v2

Thanks!
Athira

i didnt get it can share the code …is my requirement clear

Basically i need to escape “” in json string

A shift from immediate panel prototyping to modeling would look like this:
grafik

not working

@vishal_nachankar ,

If Ultimately v1 and v2 are kind of Placeholders for your desired values, we have to represent string such as v2 inside double quotes for it to be deserialized to Json.

It wouldn’t matter to your case, since we can modify the String “v2” by accessing it’s key and replace it with your desired value.

Like shown by @ppr below :

see i need to pass this whole thing as a body to http request for
{
“key1”:“value1”,
“key2”:[
“key3”:“v1”,
“key4”:v2
]
}
}
i need the final output as if try to access the key3 dircectly by config[“key2”]
i should return
[
{
“key3”:“v1”,
“key4”:v2
}
]
because i am going to pass this final output as a string body to http request

Why don’t you replace v1 and v2 with the real values before deserializing the string to a json object?

Hi team any solution for this query