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

14 Replies, 1632 Views

For a clean solution, try `pydantic` with `parse_obj_as`. Define a model with just the fields you need, and it’ll ignore the rest:

```python
from pydantic import BaseModel

class MyModel(BaseModel):
needed_field: str

data = MyModel.parse_raw(json_blob) # Automatically drops extras
```

Not *quite* `python jsondecoder omit fields`, but super tidy for structured data.

Messages In This Thread



Users browsing this thread: 1 Guest(s)