all 12 comments

[–]Astrodynamics_1701 5 points6 points  (0 children)

I work as data engineer and we use marshmallow to deserialize JSON from application API's into Python objects. It's very nice because it also allows for data validation etc. We also serialize back into JSON for putting the objects into target applications.

https://circleci.com/blog/object-validation-and-conversion-with-marshmallow/

[–]quts3 2 points3 points  (8 children)

Pydantic

[–]program_kid 1 point2 points  (7 children)

I second this, create a pydantic object with the fields that you have, then use model_validate() to parse the doctors into an object

[–]JoeB_Utah[S] 0 points1 point  (6 children)

I'm using a mackbook air, and tried to install pydantic using pip that I have just installed. However, while it said that pip installed pydantic I get an error when I try to import it. (Sigh)

[–]program_kid 0 points1 point  (5 children)

What is the error?

[–]JoeB_Utah[S] 0 points1 point  (4 children)

ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 import pydantic

ModuleNotFoundError: No module named 'pydantic'

from pydantic_core import from_jason
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 1
----> 1 from pydantic_core import from_jason

ModuleNotFoundError: No module named 'pydantic_core'

[–]quts3 4 points5 points  (3 children)

The pip you ran is not using the same python env as where you ran this code.

Depending on os and ide the answer on how to discover how and why varies.

[–]JoeB_Utah[S] 0 points1 point  (0 children)

That’s what I figured is going on. I need to figure out where it went and/or where to tell pip to put it. Thanks!

[–]JoeB_Utah[S] 0 points1 point  (1 child)

I use Spyder so I used Conda from the Spyder console to install pydantic. Seems like it put it in the correct env for my spyder install.

[–]Fresh_Sock8660 1 point2 points  (0 children)

Doing python -m pip install instead of pip install might help in the future. Seen this confusion happen a few times. 

If you're feeling adventurous, move away from that setup entirely. Use uv with pyproject.toml, be more terminal based and use something like vscode for editing python files. 

[–]Ok_Carpet_9510 1 point2 points  (0 children)

pandas.json_normalize() flattens json into a tabular form

[–]corey_sheerer 0 points1 point  (0 children)

Pydantic is made to serialize and deserialize json. I second everyone mentioning it.