Skip to content

"ValueError: Circular reference detected." exception on json5.dumps call #30

Closed
@emocibob

Description

@emocibob

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions