3 ms·
The benchmark is bad. Because after you load a json you can't really use it. Well to use it you must check lists are lists for real, objects are really objects
by LtWorf 4y ago
The benchmark is bad. Because after you load a json you can't really use it. Well to use it you must check lists are lists for real, objects are really objects and have the keys you think they should have and so on.
The alternative is using something like typedload (which I wrote) or pydantic in addition to json load, to avoid cluttering the code with the countless and error prone checks one must do to use untrusted json.
In the end dealing with untrusted json directly is terrible.
- theamk 4y agoif you are dealing with untrusted data, pickle is not an option at all, it lacks security.
- vore 4y agoIsn't pickle just as bad if not worse? There's no guarantee that the unpickled object has the right shape either, AND it can arbitrarily execute code while unpickling.
- LtWorf 4y agoIndeed, but if you say json is better and faster, you have to add all the costs, not just the parsing. Otherwise while json will not execute code, it will crash your program. And while in python it's ok, in C++ you can still execute code in that way :)