Code Monkey home page Code Monkey logo

Comments (10)

Midar avatar Midar commented on June 24, 2024

Uhm, why exactly are they disallowed? I think it makes sense to support them to denote that it's a floating number. node also seems to support them.

from json5.

aseemk avatar aseemk commented on June 24, 2024

@Midar, did you check out the discussion on pull request #9?

#9

JSON doesn't differentiate between ints and floats — it only defines a single "Number" type, and indeed, same with JavaScript — but is it the case that JSON implementations in other languages return specific types?

from json5.

Midar avatar Midar commented on June 24, 2024

Yes, other languages differentiate. In ObjFW, it's an OFNumber, but an OFNumber can contains a float, a double, an int, a size_t, etc. What it currently does is use an intmax_t for integers and a double for floating types.

Currently, it interprets 5.0 as a double and 5 as an integer. 5. would be a double then, while 5 would be an integer. It would actually make a difference if you go on and calculate something with it.

You can, of course, always convert it manually. The OFNumber class even has abstraction for that. For example, you call call [someNumber intMaxValue] and get an intmax_t - no matter whether it actually was an intmax_t or a double, it will just be converted if necessary.

However, these types have different limits, so it might actually make a difference.

What I also don't get about this is the inconsistency: Why would one allow .5, but not 5.?

from json5.

aseemk avatar aseemk commented on June 24, 2024

Good to know. I think you've made a reasonable case for allowing it. =)

from json5.

Midar avatar Midar commented on June 24, 2024

And here is another example:

@implementation Test
- (void)applicationDidFinishLaunching
{
        [of_stdout writeFormat: @"%@\n%@\n",
            [[@"[5.]" JSONValue] JSONRepresentation],
            [[@"[5]" JSONValue] JSONRepresentation]];
}
@end

Output:

[5.0]
[5]

I have to admit though that this is only since my last commit ;). OFNumber's description method was using the printf format specifier %f for floating points which would kill the decimal point if unnecessary. But since I fixed that bug in the description of an OFNumber, it behaves like pasted here. So I actually found and fixed a non-JSON5-related bug thanks to this discussion :).

from json5.

aseemk avatar aseemk commented on June 24, 2024

Happy to help! ;)

from json5.

Midar avatar Midar commented on June 24, 2024

Any progress on this? Can at least the spec be updated?

from json5.

aseemk avatar aseemk commented on June 24, 2024

Thanks for the nudge! Sorry there's been no progress on this; I've been quite busy. I can try to get to this over the holidays, but if you'd like to send a pull request, feel free! Even if it just updates the readme (but in that case, it'd nice to call out a TODO for this implementation to support it).

from json5.

aseemk avatar aseemk commented on June 24, 2024

Released in 0.2.0 FYI!

https://github.com/aseemk/json5/blob/develop/CHANGELOG.md#v020-code-diff

from json5.

Midar avatar Midar commented on June 24, 2024

Nice! Thanks!

from json5.

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.