GithubHelp home page GithubHelp logo

pretty print and ident config? about pyjson5 HOT 2 OPEN

kijewski avatar kijewski commented on September 27, 2024
pretty print and ident config?

from pyjson5.

Comments (2)

Kijewski avatar Kijewski commented on September 27, 2024 1

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.

from pyjson5.

dg-pb avatar dg-pb commented on September 27, 2024 1

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 sublime text uses? That one looked perfect tbh.

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

from pyjson5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.