How to add a non-string value in the json object in dataweave. key2 : value2 is not a string and the output should not have inverted commas.
Expected Output:
{
"key": "value",
"key1": "vale1",
"key2": value2,
"key3": "value3"
}
Asked
Active
Viewed 41 times
0

Uday
- 15
- 1
- 6
-
does this help? https://stackoverflow.com/questions/52850629/mule-dataweave-to-insert-new-json-field-in-the-existing-payload – Harshank Bansal Jul 18 '22 at 08:37
-
no, that also adds double quotes to value. I want the output value without double quotes for key2. – Uday Jul 18 '22 at 08:45
-
If the value is non-string, it will not add the quotes, but the way of adding it is same. Like this https://help.mulesoft.com/s/question/0D52T00005TViycSAD/how-to-add-a-new-key-value-pair-to-a-objectmap – Harshank Bansal Jul 18 '22 at 08:47
-
I am actually hardcoding the value "value2" in the dataweave but in the json output value2 should not come as String with double quotes. I have added the screenshot in the question. – Uday Jul 18 '22 at 08:52
-
So you want a string value in JSON without quotes. That is not a valid JSON and so not supported by dataweave. Best bet would be to write it as a string and do some string manipulation to remove the quotes – Harshank Bansal Jul 18 '22 at 11:04
-
@Uday why do you want to output it without quotes? – aled Jul 18 '22 at 11:49
-
@aled target system is expecting one field value to be without quotes. I fixed it by converting json to string and removing the quotes as Harshank suggested. – Uday Jul 18 '22 at 16:04
-
Whatever the target system is expecting is not valid JSON. – aled Jul 18 '22 at 17:00