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

Set on an innermost Container doesn't reflect the changes on actual object #84

Open
bandikishores opened this issue Jul 12, 2020 · 1 comment

Comments

@bandikishores
Copy link

I've a JSON {"name":{"first":"kishore"}} , when I try the Set Operation by loading "name"."first" It doesn't reflect the Modified Value.
However the Set Operation by loading "name" Container works.

package main

import (
	"fmt"
	"github.com/Jeffail/gabs/v2"
)

func main() {
	jsonParsed, err := gabs.ParseJSON([]byte(`{"name":{"first":"kishore"}}`))
	if err != nil {
		panic(err)
	}
	
	container := jsonParsed.S("name", "first")
	container.Set("Modified")
	fmt.Printf("Container Value : %s\n",container.Data())
	fmt.Printf("Modified Using First Container JSON : %s\n", jsonParsed.String())
	
	container = jsonParsed.S("name")
	container.Set("Modified1", "first")
	fmt.Printf("Modified Using Name Container JSON : %s\n", jsonParsed.String())
}

Actual Output:
Container Value : Modified
Modified Using First Container JSON : {"name":{"first":"kishore"}}
Modified Using Name Container JSON : {"name":{"first":"Modified1"}}

Expected Output:
Container Value : Modified
Modified Using First Container JSON : {"name":{"first":"Modified"}}
Modified Using Name Container JSON : {"name":{"first":"Modified1"}}

Playground : https://play.golang.org/p/hX1-ed4nxEi

@Jeffail
Copy link
Owner

Jeffail commented Jul 21, 2020

Hey @bandikishores, the Set function should always have at least one path parameter, otherwise you are setting a reference type that gets immediately dropped. There's maybe a case for panicking here in order to prevent the silent failure.

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