Jeffail/gabs

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

Opened this issue · 1 comments

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

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.