Skip to content

L is not JSON-serializable #531

@criemen

Description

@criemen

The documentation for L claims that it is a drop-in for list operations.
Unfortunately, that's not entirely true, unlike true lists, L is not JSON-serializable:

Traceback (most recent call last):
  File "/Users/criemen/repos/codeql-halo/plugins/custom_github/operators/actions.py", line 121, in workflow_finished
    artifacts_str = xtras.dumps(artifacts)
  File "/opt/homebrew/lib/python3.10/site-packages/fastcore/xtras.py", line 152, in dumps
    return json.dumps(obj, **kw)
  File "/opt/homebrew/Cellar/python@3.10/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/opt/homebrew/Cellar/python@3.10/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/homebrew/Cellar/python@3.10/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/opt/homebrew/Cellar/python@3.10/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type L is not JSON serializable

This is rather annoying, as ghapi apparently returns L objects, instead of python lists, and besides a recursive traversal of the resulting object that I'd have to write myself, I've not found any easy way to convert an object/dist into something that I can JSON-serialize. Can you help me?
Is there any way you can make L work with JSON serialization? It doesn't work with json.dumps, and not even with your own xtras.dumps either 😞

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