'update json string in scala using jackson
I have a json
val nodeJson =
s"""
{
"NAME":"node1",
"CONFIG":{
"colMap": {
"idcols": [
],
"emailcols":[
]
},
"col.partitions": "3"
}
}
"""
I have to populate "idcols" and "emailcols" array dynamically from scala array.
like if i have arrays:
val idcols = Array("per_id","dep_id")
val emailcols = Array("per_email","dep_email")
then these values need to set in the json string
I have to use com.fasterxml.jackson library.
I am able to get the arrays:
val obj = new ObjectMapper()
val root = obj.readTree(nodeJson)
val value = root.get("CONFIG").get("colMap")
println(value)
But I am not sure how to update it and set it back to the json. Kinldy let me know how can i update the json string.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
