-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pretty print and ident config? #19
Comments
Pyjson5's parser does not preserve the comments or whitespaces. So the serializer is nearly identical to standard json.dump(s), except that pyjson5's output is HTML-safe and ASCII-only. If you need pretty printed data, then most likely you don't want either, because it hurts readability; and speed is also most likely quite unimportant, because it's not a lot of data to have to serialize. So I guess you could use pyjson5 for parsing, and json for stringifying. |
I agree with sbant. Pretty printing is a desirable feature. After all, json5 emphasises on human friendliness, comments, etc. Using this parser a lot of it is lost. However, the speed is amazing, nothing compares to it. And in some cases both are needed, e.g. real-time speed crucial app that needs to track config changes, which are potentially a manual user input. dump(load(string)) == string, would be great to have as an option, even if a bit slower. And another package is unbelievably slow. Yaml is too slow, json is too raw, II was hoping to find a happy middle. Many are too complex, others at the risk of extinction, etc, etc... Difficult choice to be honest. Benchmarked this package against a great lot and all looked great - happy middle, but this is a bit of a dealbreaker. For now, I will use abstracted orjson so I can swap later given I find a happy middle I was after. Maybe you know what sort of config parser Adding benchmarks for reference: print(timeit.timeit('json.loads(json_text)', number=N, globals=globals()))
print(timeit.timeit('ujson.loads(json_text)', number=N, globals=globals()))
print(timeit.timeit('orjson.loads(json_text)', number=N, globals=globals()))
print(timeit.timeit('pyjson5.loads(json_text)', number=N, globals=globals()))
# print(timeit.timeit('yaml.load(json_text, Loader=Loader)', number=N, globals=globals()))
print(timeit.timeit('yaml.load(json_text, Loader=CLoader)', number=N, globals=globals()))
# 0.27317825198406354
# 0.12556396395666525
# 0.0474954119999893
# 0.12391428096452728
# 42.89380981097929
# 5.733772745996248
print(timeit.timeit('json.dumps(data)', number=N, globals=globals()))
print(timeit.timeit('ujson.dumps(data)', number=N, globals=globals()))
print(timeit.timeit('orjson.dumps(data).decode()', number=N, globals=globals()))
print(timeit.timeit('pyjson5.dumps(data)', number=N, globals=globals()))
# print(timeit.timeit('yaml.dump(data, Dumper=Dumper)', number=N, globals=globals()))
print(timeit.timeit('yaml.dump(data, Dumper=CDumper)', number=N, globals=globals()))
# 0.28529386199079454
# 0.10934980498859659
# 0.03539454500423744
# 0.1855485350242816
# 19.672126159013715
# 5.398652292031329 |
No description provided.
The text was updated successfully, but these errors were encountered: