Skip to content

Question: How to update JSON at path #37

Description

@zerodefect

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions