Closed
Description
When I call json5.dumps
on a previously loaded and modified object, I get the following exception:
ValueError: Circular reference detected.
My environment info:
- Ubuntu 19.04
- Python 3.7.3
- json5 0.8.5
Code to recreate the issue (I know there's a logical error since REGION
is modified for both development
and t
):
import json5
def demo():
js_object_str = """{
development: {
REGION: "foo",
},
prod: {
REGION: "baz"
}
}"""
all_configs = json5.loads(js_object_str)
new_config = all_configs["development"]
new_config.update({"REGION": "bar"})
all_configs["t"] = new_config
print(all_configs)
print(json5.dumps(all_configs)) # this causes the error
demo()
Workaround:
Import from copy import deepcopy
and change all_configs["t"] = new_config
to all_configs["t"] = deepcopy(new_config)
.
Metadata
Metadata
Assignees
Labels
No labels