08-10-2022 08:52 AM
Hi All,
I am creating a Json file by using the Json formatter but I am not getting the json in correct format for all the empty values.
Below is the input for Json Formatter :
Getting below output from Json Formatter.
The output should look like below. Empty fields should be enclosed in double codes.
“Bankgroup” : “”,
“BankNumber” : “”,
Please let me know how we can achieve this.
@dmiller
Thanks
Mohit
08-10-2022 09:38 AM
Hi Mohit!
What you might try is passing that JSON over to a mapper, and using the mapper to do what you want.
Turn off pass through in the mapper and use an expression language statement to convert everything to a string like this:
$.mapValues(x=>x == null ? "" : x.toString())
This will essentially set everything to a string, even an empty string.
Here’s what my mapper looks like to do this:
Hope that gets you closer!
– David
08-10-2022 09:58 AM
@djsiegel I am not using the pass through. I am just mapping the fields in mapper snap and then sending it to Json formatter snap to generate the Json but it is only showing single quotation mark for empty values.
I tried your expression as well but it is also not working.
08-10-2022 12:00 PM
Mohit, this is just an odd bug in the Designer’s viewer for JSON preview data. If you actually save the output of the JSON Formatter to a file using a File Writer, you’ll see that the empty string is a pair of double quotes as you expect.
08-10-2022 12:13 PM
Can confirm, Patrick - I happened to just be building an example to test myself.
When I download it, I do see the doublequotes.
Mohit - here’s my example, with both the input and output. Hope that helps.
CommunityExampleJSON.zip (4.3 KB)