GithubHelp home page GithubHelp logo

Comments (8)

haskellcamargo avatar haskellcamargo commented on June 12, 2024 2

The behavior is correct, @ppamorim.
According to any JSON RFC specification, the first entry must be a JSON-valid expression. Empty string is a syntax error. No matches for ", {, [, \d, true, false or any other valid start token.

from klaxon.

haskellcamargo avatar haskellcamargo commented on June 12, 2024 2

Almost every parser of JSON will throw unexpected end of input. A JSON parser will look for a valid start token, such as STRING, TRUE, FALSE, OPEN_BRACE, OPEN_BRACKET or QUOTE. But, in that case, after trying all these, the found token was EOF, therefore it was unexpected.

It's default behavior, as you can see on Chrome default JavaScript implementation.
2017-08-18-165305_374x97_scrot

from klaxon.

damphat avatar damphat commented on June 12, 2024 1

Hi @ppamorim

According to http://www.json.org, empty string is not a valid json.

> JSON.parse("")
SyntaxError: Unexpected end of JSON input

If you want to add non-strict mode for klaxon then the Parser should return null for empty string.

from klaxon.

damphat avatar damphat commented on June 12, 2024 1

parse("") MUST throws an error.

WHY?
There are a lot of projects that depends on klaxon, they may use that Exception for detecting error, validate user input, etc.

Even if you want to return null, you must explicitly provide an option for example:

val parser = Parser(Parser.NonStrict)
parser.parse("") // return null

from klaxon.

ppamorim avatar ppamorim commented on June 12, 2024

@damphat Null means anything, we need to find a better solution for that fallback. Maybe returning Nothing?

from klaxon.

ppamorim avatar ppamorim commented on June 12, 2024

@haskellcamargo The behavior is correct but the way that the library currently handles the exception doesn't help. Returning a null or nothing can be better.

from klaxon.

ppamorim avatar ppamorim commented on June 12, 2024

It can use a clear Exception for a strict configuration, it's more sensible. I noticed that the parser does a lot of verification/setup and then thrown the error. Is that correct?

from klaxon.

ppamorim avatar ppamorim commented on June 12, 2024

@damphat I did changes on my pull request. Would you like to have a look on it? Thank you.

from klaxon.

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.