Code Monkey home page Code Monkey logo

Comments (3)

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

Since you are doing two very different things (conversion, and then validation), I would definitely apply the 'separation of concerns' principle here. If the data coming in (the 'string') is supposed to be a dict, you could attempt a conversion with the ast.literal_eval builtin (Py2.6+).

literal_eval(node_or_string)
    Safely evaluate an expression node or a string containing a Python
    expression.  The string or node provided may only consist of the following
    Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
    and None.

I suspect it wouldn't be enough, thought, but it could be a good starting point. In Eve I am using simplejson/json loads method to obtain a dict out of query strings and request form data.

from cerberus.

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

Also, since you mention dates in JSON streams, did you check JSON-Datetime? It's a little toy of mine, built when I was experimenting with JSON and conversion issues. The Eve implementation is slightly different though.

from cerberus.

martijnvermaat avatar martijnvermaat commented on July 23, 2024

I think you are right and I should separate concerns. Thanks for the pointer to JSON-Datetime, I'll check it out.

from cerberus.

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.