AnswerDotAI / AnswerDotAI/fastcore

`L` is not JSON-serializable

Open
#531 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
1.1k
Forks
295
Avg merge
1d 6h
Merged PRs (30d)
7

Description

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 😞

Contributor guide

Open the contributing guide

Research direction

Start by examining L and the xtras.dumps entry point, then reproduce the failure with Python's json.dumps and xtras.dumps as shown. Determine the supported conversion or serialization behavior for L objects, including nested values, and verify that the reported use case produces valid JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.