'Add double quotes to JSON input using groovy script
I'm working with Json file and the json structure is incorrectly formatted. I would like to add double quotes (") in the below JSON using groovy scripting.
Input File:
{"I_BEGDA":2020-01-01,"I_ENDDA":2020-01-21,"I_TOTAL":"X"}
Expected Output:
{"I_BEGDA":"2020-01-01","I_ENDDA":"2020-01-21","I_TOTAL":"X"}
I tried multiple scripts but none of them looks working. Appreciate your help in fixing the same.
Thanks
Solution 1:[1]
Try something like this:
import groovy.json.*
def input ='{"I_BEGDA":2020-01-01,"I_ENDDA":2020-01-21,"I_TOTAL":"X"}'
def output = new JsonBuilder(
new JsonSlurper().with { it.type = JsonParserType.LAX ; it }.parseText(input)
)
println(output)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | BalRog |