Comments (10)
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.
@Midar, did you check out the discussion on pull request #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.
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.
Good to know. I think you've made a reasonable case for allowing it. =)
from json5.
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.
Happy to help! ;)
from json5.
Any progress on this? Can at least the spec be updated?
from json5.
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.
Released in 0.2.0 FYI!
https://github.com/aseemk/json5/blob/develop/CHANGELOG.md#v020-code-diff
from json5.
Nice! Thanks!
from json5.
Related Issues (20)
- Security Vulnerability issue HOT 1
- core-js@<3.4 has been deprecated HOT 1
- JSON5.parse error with `{actions: ['login']}`
- `stringify` should throw when serializing a BigInt like `JSON.stringify` does HOT 8
- Rename `master` branch to `main` HOT 1
- Explain use cases front and center HOT 3
- Module '"node_modules/json5/lib/index"' has no default export HOT 1
- Support Integers outside the range `[-(2**53)+1, (2**53)-1]` HOT 6
- SyntaxError when require()ing JSON5 file in Jest test HOT 1
- Prototype Pollution in JSON5 HOT 11
- json5 latest is now 1.0.2 on npmjs - intentional? HOT 3
- Support Template Literals using backticks? HOT 1
- Provide `exports` config in `packages.json`
- Multiline JSON doesn't multiline HOT 1
- add key property support ? HOT 1
- Add `comma-dangle` option
- Online JSON5 Editor(Formatter) is misleading? HOT 2
- Use .substring() instead of the deprecated .substr()
- Cannot stringify "\u0000"
- transitive dependency 'minimist' needs to be updated by rebuilding HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json5.