changing one dictionary value changes another

data = JSON.parse_string(containers_file.get_as_text())
#data { "bike_box": { "items": ["", "bullet", "bullet", "", "", "", "", "bullet", "bullet", ""] }, "box": { "items": ["bullet", "", "", "", "", "", "", "", "", ""] }, "inventory": { "items": ["bullet box", "bullet", "bullet", "", "", "", "", ""] } }
...
data[container_name]['items'] = container_text
#container_text ["", "", "bullet", "", "", "", "", "", "", ""]

this code is supposed to change the value of bike_box[‘items’] or box[‘items’] depending on container_name, but it changes both values no matter what container_name is

Is it possible that both containers reference the same dictionary?

yes, thank you very much, this was the problem

		data[container_name]['items'] = container_text.duplicate(true)

this version works

1 Like