Skip to content

Calling Set on nested JSON object returns invalid JSON after setting value #218

Description

@karanssh

If I call set on a deep nested JSON, the value after it returns misses the quotes required for a valid JSON

Input JSON:

{
		
			  "ipv4":{
				 "name":"testDependency",
				 "source":{
					"address":{
					   "group":"testDepenffdency",
					   "ff":"aa"
					},
					"port":{
					   "any":true
					}
				 },
				 "uuid":"653e5654-b56b-47c1-b4e5-206acbb28f7a"
			  }
	 }

code invoked:

keysList := []string{"ipv4", "source", "address", "group"}
	setVal := []byte(`KaranTest`)
	outputVal, err := jsonparser.Set([]byte(buggedString), setVal, keysList...)

Output:

	 {

		"ipv4":{
			   "name":"testDependency",
			   "source":{
					  "address":{
						 "group":KaranTest,
						 "ff":"aa"
					  },
					  "port":{
						 "any":true
					  }
			   },
			   "uuid":"653e5654-b56b-47c1-b4e5-206acbb28f7a"
		}
}

Here's an example of the problem: https://play.golang.org/p/YT3Ttz0Irib

However, if I pass :

setVal := []byte(`"KaranTest"`)

It works as expected. Most of the time in programs we don't get strings like that. Is this by design? 😊 I'll have to wrap strings around " " to get around this issue.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions