{ number: 1.0000000000000000000000000000001 }
Try parsing the above JSON consistently in several languages without a consistent schema definition. { number: 1.0000000000000000000000000000001 }
Try parsing the above JSON consistently in several languages without a consistent schema definition.And what exactly do you mean by "semantics around type handling are implied", especially in `{ number: 1.0000000000000000000000000000001 }` case?
Run it through JSON lint ( http://jsonlint.com/ ), then fix the error (unquoted number text), then run it again and watch the data loss occur due to my original point...
{ number: "1.0000000000000000000000000000001" }
How is it worse than XML?
It's conceptually easier to think about JSON with simple data sets but it's terribly inflexible and you have to think about how things are represented inside strings. A couple of thought exercises on JSON:
1. How do you represent an image inside JSON?
2. How do you represent a reference to another part of the data in JSON (consider a DAG for example)?
3. How do you represent an ordered set or an unordered set in JSON?
4. How do you represent an unsigned value in JSON?
Use the right tool for the job.
Sure, if you don't consider "human-readable" a good justification. Some of us do.
No, they don't.
> Imagine HTML in JSON.
Yes, sure, JSON is a crappy text markup language, and would be much less readable than HTML for that purpose.
OTOH, readability when used as a markup language for content consisting largely of prose text and readability when used as a structured serialization format for data that doesn't mostly consist of large blocks of annotated prose isn't necessarily the same thing.
That's a highly-subjective and controversial point.
(To me, XML is the Java of data languages -- its a lot worse than the best alternative considered on its own for almost any purpose -- though the best alternative will vary by purpose -- but it has a fairly wide range of uses for which its not intolerably bad, and its often a better choice than its inherent features would suggest because of the strength and maturity of the ecosystem around it.)
For 100% of the XML feature-set I don't actually know of a viable alternative. If you are using XML for the right reasons and the right way (rare) there is currently little or nothing that can replace. That being said, there are a vanishingly small amount of problems that actually require XML - namespaces and extensibility are two of them.
Real problems rarely need 100% of the XML feature set to solve. The breadth of the feature set is why there are lots of problems for which XML is a tolerable solution based on its inherent features (which in turn is a big factor in why it has such a large ecosystem), but they often don't make it the best solution (especially before considering the ecosystem, which is important in choosing a tool, but not a reason to avoid developing a new alternative, since any new alternative is going to start with an ecosystem disadvantage, but with adequate inherent value should be able over time to gather an ecosystem of tools.)
#/usr/bin/python n = 1.0000000000000000000000000000001 print n # 1.0
//Javascript n = 1.0000000000000000000000000000001; console.log(n); // 1
from decimal import Decimal
n = Decimal("1.0000000000000000000000000000001")
just because float is the default, doesn't mean you have to use it. JSON doesn't have anything else, though.Type this in your address bar for an illustration:
javascript:alert(1.0000000000000000000000000000001);
So where can we go here. Yep: { number: "1.0000000000000000000000000000001" }
which means we then break the encapsulation boundary of the metadata. Then we have a wire contract that says "this is a string" and a separate semantic contract that says "this is a decimal".XML:
<number>1.0000000000000000000000000000001</number>
Schema: <xs:element name="number" type="xs:decimal"/>
This is just one example. We can also serialize and deserialize complex self-relational composite types transparently at both ends of the channel.This is a real world problem we encounter in the financial sector every day.
javascript:alert(1.000000000000001);
{ "number": "1.0000000000000000000000000000001" }
along with { "number": { "type": "ModelReal", precision: 64 } }
versus <number>1.0000000000000000000000000000001</number>
along with <xs:element name="number" type="xs:decimal"/>
In each case you have text data given meaning by an external semantics enforced via a schema. The real and unavoidable downside is that JSON actually contains a really lousy primitive. It wouldn't be bad except practically every implementation of JSON automatically performs a lossy coercion to IEEE floats.All minimally conforming processors must support decimal numbers with a minimum of 18 decimal digits (i.e., with a totalDigits of 18).
You have 32 decimal digits in 1.0000000000000000000000000000001, so "minimally conforming processors" are, according to spec, actually free to drop everying after 17th place after comma in this case.
You say "constraints of the type are undefined". I don't see how "double-precision 64-bit format IEEE 754 value" from ECMAScript spec is lesser defined than "decimal numbers with a minimum of 18 decimal digits".
You're right about decimal precision however so I conceded there but the precision and capability is defined.