Coder Social home page Coder Social logo

TypeCoercion like ajv about fast-json-stringify HOT 5 OPEN

Uzlopak avatar Uzlopak commented on June 9, 2024
TypeCoercion like ajv

from fast-json-stringify.

Comments (5)

Uzlopak avatar Uzlopak commented on June 9, 2024 1
const fastJson = require('fast-json-stringify')

const stringify = fastJson({
  title: 'Example Schema',
  type: 'object',
  properties: {
    boolean: {
      type: 'boolean'
    }
    }
})

console.log(stringify({
    boolean: "false"
}))

results in "{\"boolean\":true}"

awesome

from fast-json-stringify.

jsumners avatar jsumners commented on June 9, 2024

To what end? AJV is coercing JSON into JavaScript natives. FJS is converting JavaScript natives into JSON.

from fast-json-stringify.

ivan-tymoshenko avatar ivan-tymoshenko commented on June 9, 2024

Not a good example IMHO. With the same result, you can complain about the js standard.
!!"false" === true

but I also don't like some types coercions that we have. The question is what should we do in this case?

  • throw an error
  • return { boolean: "false" }
  • return { boolean: false }
  • return { boolean: true }
    return {}

from fast-json-stringify.

Uzlopak avatar Uzlopak commented on June 9, 2024

The risk that I see here is about diverging behaviour between ajv and fsj. Then we have some cases were ajv validates as valid and fsj maybe throws or serializes it differently. Also we potentially need to coerce the vaues if we want to process them for stuff like const and enum. If we want to go that way.

from fast-json-stringify.

Eomm avatar Eomm commented on June 9, 2024

I'm pro to good coercion default and not throwing.

from fast-json-stringify.

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.