Skip to content

Summary of unsolvable problems. #21

Description

@hhaoao
import json
from types import SimpleNamespace

data = '{"$123": "456", "name": "John Smith", "hometown": {"name": "New York", "id": 123}}'

# Parse JSON into an object with attributes corresponding to dict keys.
x = json.loads(data, object_hook=lambda d: SimpleNamespace(**d))
print(x.name, x.hometown.name, x.hometown.id)
print(x.$123)        # Errors can occur here
print(getattr(x.asdf[0], "$sdf"))        #  get variables.
from jsonpath import JSONPath

data = { "$aa": [{"$bb": "123"}] }        # dict
field_data = "$.'$aa'[0].'$bb'"
a  = JSONPath(field_data).parse(data)
print(a)       # ['123']

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions