jsonparser icon indicating copy to clipboard operation
jsonparser copied to clipboard

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

Open karanssh opened this issue 5 years ago • 5 comments

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.

karanssh avatar Nov 29 '20 12:11 karanssh

yes,I found it, too

miscomputer avatar Feb 15 '21 19:02 miscomputer

I got this issue today

soulmachine avatar Mar 25 '21 13:03 soulmachine

I found this too, any update?

blake86 avatar May 25 '21 07:05 blake86

I get this issue too. How to deal with it?

wmz2014 avatar Sep 05 '22 02:09 wmz2014

I found a way to deal with it image

wmz2014 avatar Sep 05 '22 02:09 wmz2014