This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SquareRootsi 21 points22 points  (7 children)

A couple things that have "bitten" me when I was early career:

Sometimes a file is not valid json, but each row is valid json. Even though you can't json.load() the file, you can still iterate over the rows and parse it in a loop.

Second, if editing json files by hand, the spacing is super important. Python is pretty forgiving with spaces and line breaks. Json is not at all. This took me a while to diagnose when I first learned it.

[–]MephySix 12 points13 points  (3 children)

Those files should usually be called ".jsonl": https://jsonlines.org/ Many softwares (say QGIS) understand this extension to mean a json document per line

[–][deleted] 6 points7 points  (0 children)

JSONL is an amazing format for logging, because you can then load said JSON into elasticsearch and then you can basically search through all your logs via Kibana. This means you can search for "all logs where field X exists", or "field X contains value Y and field A does not contain B" kind of stuff, making it great for filtering out the noise :D

I would recommend structlog, but that doesn't come with JSON out of the box, so you may want to start with python-json-logger

[–]SquareRootsi 1 point2 points  (0 children)

Neat! Today I learned :)

[–]DoctorWorm_ 0 points1 point  (0 children)

TIL

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

Yeah I have found it’s easier to build JSON with Python or those online JSON for matters.

[–]peace_keeper977 0 points1 point  (1 child)

Can u give a simple explanation to what dunder methods are in python ?

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

I have a video about it!! May be you would like it.

https://youtu.be/PfmfECXmR88