adafruit / adafruit/Adafruit_CircuitPython_JSON_Stream

A value of null is not understood

Open
#12 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2
Forks
7
PR merge metrics
No merged PRs in 30d

Description

In json "null" is a valid value for an item in a list or object. `json.loads("null")` returns `None`.
Because `next_value` returns `json.loads(value_string)` or `None` (or a Transient subclass), and that value is compared to `None`, a list like [1,2,null,3,4,5] is wrongly interpreted.
Here is a comparison with `json_stream` too.

```py
import adafruit_json_stream
import json_stream
import io

def test_null_item(json_stream):
print("-"*10)
source = io.BytesIO(b'[1,2,null,3,4]')
stream = json_stream.load(source)
for item in stream:
print("-", item)

test_null_item(adafruit_json_stream)
test_null_item(json_stream)
```
```
----------
- 1
- 2
----------
- 1
- 2
- None
- 3
- 4
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at next_value and reproduce the issue with the provided io.BytesIO example, comparing iteration over [1,2,null,3,4]. Done means a JSON null item is yielded as None and iteration continues through the remaining values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.