Giter Site home page Giter Site logo

Parsing JSON directly about pydantic-core HOT 5 CLOSED

pydantic avatar pydantic commented on September 16, 2024 1
Parsing JSON directly

from pydantic-core.

Comments (5)

samuelcolvin avatar samuelcolvin commented on September 16, 2024 1

The options are:

  • parse to python, then pass to validate_python which is fine, but slow
  • adding more formats to pydantic-core, this is fairly easy but will increase the binary size and have a maintenance burdon, so a format would need to be fairly widely used to be added - only yaml and toml could be considered I think
  • We might be able to find some way to pass a JsonInput from rust to python, then back from python to rust in a safe way and thereby allow a library which pydantic-core doesn't know about create the JsonValue with pydantic-core consumes - thereby getting most of the performance gain

But I don't know if that's possible, it would probably be "unsafe" e.g. if you passed a pointer to something other than a JsonValue, you'd get a segfault. It's something to think about in future probably.

from pydantic-core.

samuelcolvin avatar samuelcolvin commented on September 16, 2024 1

If you have a model for "plugins" that's well developed, please explain - I can't see how that would work, but maybe I'm missing something.

from pydantic-core.

griels avatar griels commented on September 16, 2024

I am using Pydantic quite heavily in tandem with our own CBOR parsing code. It would be great if we could plug in an arbitrary serde codec (such as ciborium) rather than just serde-json. But I think using serde-json would be a great start.

from pydantic-core.

griels avatar griels commented on September 16, 2024

See also the work in orjson which does a partial decode/encode of pydantic structures (but misses many of the fancier features).

As a total Rust noob, I made a POC fork of orjson with CBOR support: https://github.com/griels/orjson/tree/cbor-support-mk2 so it's quite simple to work in different codecs.

from pydantic-core.

griels avatar griels commented on September 16, 2024

Thanks, I'll have to think about it. It seems there isn't an obvious ABI Rust code can offer for 'plugins', short of wrapping in a C FFI (maybe something like the JSONInput you mention), so I guess otherwise serde codecs might have to be injected at the source code level. Perhaps there is someone who has already tackled this. Apologies for necroposting by the way! 'Plugging' ciborium straight into Pydantic has been something I wanted to do for some time so I got excited.

from pydantic-core.

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.