I have a JSON structure that looks like:
{
"A": {
"NestedArray": [
{
"AlreadyHere2": "x"
},
{
"AlreadyHere2": "x"
},
{
"AlreadyHere2": "x"
}
]
}
}
I need to add new Json fields with the same CONSTANT value to specific parts of the existing json document so it becomes:
{
"A": {
"A_1": "CONSTANT",
"A_2": "CONSTANT",
"NestedArray": [
{
"AlreadyHere2": "x",
"arrayValue": "CONSTANT"
},
{
"AlreadyHere2": "x",
"arrayValue": "CONSTANT"
},
{
"AlreadyHere2": "x",
"arrayValue": "CONSTANT"
}
]
}
}
Note: in the case for arrays, add CONSTANT to each element.
I have a list of the specific json paths available to use as a “traversal guide” that could have more values added to in the future so my implementation can’t be tailored to the existing json structure. i.e.:
val list = List("A.A_1", "A.A_2", "A.NestedArray.arrayValue")
I see that there’s this for recursively modifying JSON: https://circe.github.io/circe/optics.html#recursively-modifying-json
but I am not sure how I can handle adding to specific new fields and in arrays. Any help would be greatly appreciated, thank you!