Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to update JSON at path #37

Open
zerodefect opened this issue Jun 10, 2023 · 1 comment
Open

Question: How to update JSON at path #37

zerodefect opened this issue Jun 10, 2023 · 1 comment

Comments

@zerodefect
Copy link

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.

@mdzhigarov
Copy link

I'm also interested in that. Have you found a way to update the json at path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants