How to omit fields when using Python JSONDecoder? or Python JSONDecoder omit fields - is there a clea

14 Replies, 1634 Views

If you're stuck with `python jsondecoder omit fields`, here's a hacky but fun way:

Monkey-patch `json.decoder.scanstring` to bail early if the key matches your blacklist.

*Disclaimer*: This is cursed and might break things. But it *does* skip parsing entirely for unwanted keys.

```python
original_scanstring = json.decoder.scanstring
def patched_scanstring(*args, **kwargs):
# ... magic to check keys ...
return original_scanstring(*args, **kwargs)
json.decoder.scanstring = patched_scanstring
```

Use at your own risk.

Messages In This Thread



Users browsing this thread: 1 Guest(s)