jsonpath
jsonpath copied to clipboard
Question: How to update JSON at path
I'm new to golang, so my question probably more stems from a lack of knowledge, but I'm getting there.
I have a small JSON sample that looks like the following:
{
"FullOTAConfig": {
"Licensing": {
"isLicensed": true,
"canTerminate": false
},
"BirdGlobal": {},
"Tenants": {
"Tenant1_Config": null,
"Tenant2_Config": null,
"Tenant3_Config": null
}
}
}
I am able to retrieve the JSON that I'm interested at path $.FullOTAConfig.Licensing
via:
// JSON map interface
jsonInput map[string]interface{}
// Load some JSON
// ...
// ...
// Get JSON at the requested path
subJson, err := jsonpath.Get(jsonPath, jsonInput)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// How do I update the JSON at path 'jsonPath'?
// ... ???
// jsonInput[?] = new_json_object
but what I would like to do is once the subobject is returned, I want to update the 'jsonInput' var but I don't know how I can use the jsonpath to then update the JSON in the map based on the path.
I'm also interested in that. Have you found a way to update the json at path?