Live data from Hacker News

JSON5 Data Interchange Format

json5.org

61–70 of 157 posts

Re: JSON5 Data Interchange Format

#61
post #21

I know it’s not trendy but consider XML and schema at this point. XML allows all this to be expressed and more and schema allows the creation of integration contracts that can be validated at both ends. Tooling and libraries are mature.

XML has two big problems:

1. It's super verbose. Everybody hates writing it. And yes, people do write JSON by hand.

2. It has a weird and confusing data model with both attributes and child elements. Do you do or 1? In many many cases it's ambiguous and you end up with a weird mix, whereas in JSON it's obvious and easy.

Re: JSON5 Data Interchange Format

#62
post #23
post #18

… could’ve at least disallowed for one of the most batshit crazy aspects of JSON, the legal but undefined behaviour of duplicate keys in objects. > An object whose names are all unique is interoperable in the sense that all software implementations receiving that object will agree on the name-value mappings. When the names within an object are not unique, the behavior of software that receives such an object is unpre…

It would lose its "backwards compatible" property though.

This can be solved if you base JSON5 on I-JSON (RFC 7493) instead of JSON (RFC 8259). Many (but not all) JSON implementations actually expect I-JSON, at least for object keys.

Re: JSON5 Data Interchange Format

#63
post #23
post #18

… could’ve at least disallowed for one of the most batshit crazy aspects of JSON, the legal but undefined behaviour of duplicate keys in objects. > An object whose names are all unique is interoperable in the sense that all software implementations receiving that object will agree on the name-value mappings. When the names within an object are not unique, the behavior of software that receives such an object is unpre…

It would lose its "backwards compatible" property though.

Having a defined, predictable behaviour in JSON5 doesn't seem like it would break backwards compatibility with JSON's undefined, unpredictable behaviour. I don't think someone with an existing JSON document would complain that a JSON5 parser behaved "too predictably" when interpreting their document.

Re: JSON5 Data Interchange Format

#64
post #57

Earlier quoted context omitted.

It allows you to put double quotes in the string without escaping them, which is pretty nice.

But then you can't include single quotes into the string any more. Same problem again. The most practical solution for this problem I saw was in F#. You can use tripple-quoted strings. let a = """The diner is called "John's", but you can't let the string end with a double quote""" https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...

Rust has similar but it scales infinitely. They're called raw strings,

  "normal string can contain ' "
  r#" raw string can contain " ' "#
  r###" if for some reason you need to write "#  "###
Kinda like heredocs

Re: JSON5 Data Interchange Format

#65
post #4

Couple of gripes: - Still no date type - Why make it more loose? Like "Strings may be single quoted." doesn't bring any value.

It brings it closer to JavaScript behavior I guess. I guess it's nice to have ability to copy random js object declaration to actual json without editing

Re: JSON5 Data Interchange Format

#67
post #44
post #36

Earlier quoted context omitted.

All text based data formats are meant to be human readable and human writable, and humans read and write JSON all the time.

You wouldn't say that mammals write C all the time, would you? Front end development would be so much better if you could just spew json at people in a table.

>You wouldn't say that mammals write C all the time, would you?

Yes. Mammals do write C all the time, because humans are mammals. And C is meant to be human readable and writable.

> Front end development would be so much better if you could just spew json at people in a table.

That's literally what a JSON API is, and there are tons of them. And for each of them, a human had to be able to read and comprehend JSON responses and write JSON requests in code. There's a reason JSON is pretty-printed in the debug consoles of browsers.

To say nothing of all of the package definitions or framework configs that are written (by hand) in JSON.

The fact that most JSON is machine generated at present has nothing to do with its original design intent. Most Javascript, CSS and HTML are machine generated nowadays as well, but they were meant to be written by a person using a text editor.

Re: JSON5 Data Interchange Format

#68
post #50
post #21

I know it’s not trendy but consider XML and schema at this point. XML allows all this to be expressed and more and schema allows the creation of integration contracts that can be validated at both ends. Tooling and libraries are mature.

XML is a terrible data interchange format because it embeds its schema in its data. That makes it sometimes an order of magnitude larger, and it takes longer to parse. If you want to drop JSON altogether, something like Protobufs would be better. But JSON + JSONSchema has all the benefits of XML and none of the drawbacks.

XML DTDs were inherited from SGML. They can also be defined externally, but with internal links to them embedded in the document.

XML Schema were supposed to fix all the problems of DTDs, but they don't support unordered content, and have a host of their own problems. XML Schema are typically external XML documents referenced by an xsi:schemaLocation attribute, but apparently you can embed them too. But I don't know if that's a common practice, since it's a pretty bad idea for a lot of reasons:

https://www.herongyang.com/XML/XSD-Statements-Embedded-in-XM...

You raise a good point that it's a bad idea to embed schemas in documents, or even references to schemas in documents, because, as James Clark points out, magic schema attributes in documents (like xsi:schemaLocation) pre-suppose that there can be only one way of validating a document, they create security and interoperability problems, and it infects documents with the namespace of the grammar that you're using to validate them, when documents shouldn't depended on such knowledge, and be forced to include hot messes of namespace attributes like:

http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0... http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

Schema Wars: XML Schema vs. RELAX NG (1/2) - exploring XML:

https://web.archive.org/web/20190403171512/http://webreferen...

>James Clark, leader of the technical committee at OASIS for RELAX NG, and author of one of the first XML parsers, recently described the problems of the XML Schema language in a newsgroup posting: [...]

>7) Magic schema attributes in documents

>W3C XML Schema provides the xsi:schemaLocation attribute, which allows an XML document instance to indicate the schema that should be used to validate the document. This creates problems with security (the destination might have changed or tampered with), interoperability (use of schemaLocation is optional) and "purity" of schema definition: There is no way to prevent the document containing magic xsi:* attributes, so the use of W3C XML Schema "infects" the grammar you are defining.

Here's more of what he has to say about JSON in his blog post "XML vs the Web":

https://blog.jclark.com/2010/11/xml-vs-web_24.html

>[...] From this perspective, my reaction to JSON is a combination of "Yay" and "Sigh".

>It's "Yay", because for important use cases JSON is dramatically better than XML. In particular, JSON shines as a programming language-independent representation of typical programming language data structures. This is an incredibly important use case and it would be hard to overstate how appallingly bad XML is for this. The fundamental problem is the mismatch between programming language data structures and the XML element/attribute data model of elements. This leaves the developer with three choices, all unappetising:

>- live with an inconvenient element/attribute representation of the data;

>- descend into XML Schema hell in the company of your favourite data binding tool;

>- write reams of code to convert the XML into a convenient data structure.

>By contrast with JSON, especially with a dynamic programming language, you can get a reasonable in-memory representation just by calling a library function. [...]

>There's a bigger point that I want to make here, and it's about the relationship between XML and the Web. When we started out doing XML, a big part of the vision was about bridging the gap from the SGML world (complex, sophisticated, partly academic, partly big enterprise) to the Web, about making the value that we saw in SGML accessible to a broader audience by cutting out all the cruft. In the beginning XML did succeed in this respect. But this vision seems to have been lost sight of over time to the point where there's a gulf between the XML community and the broader Web developer community; all the stuff that's been piled on top of XML, together with the huge advances in the Web world in HTML5, JSON and JavaScript, have combined to make XML be perceived as an overly complex, enterprisey technology, which doesn't bring any value to the average Web developer.

>This is not a good thing for either community (and it's why part of my reaction to JSON is "Sigh"). XML misses out by not having the innovation, enthusiasm and traction that the Web developer community brings with it, and the Web developer community misses out by not being able to take advantage of the powerful and convenient technologies that have been built on top of XML over the last decade.

>So what's the way forward? I think the Web community has spoken, and it's clear that what it wants is HTML5, JavaScript and JSON. XML isn't going away but I see it being less and less a Web technology; it won't be something that you send over the wire on the public Web, but just one of many technologies that are used on the server to manage and generate what you do send over the wire.

>In the short-term, I think the challenge is how to make HTML5 play more nicely with XML. In the longer term, I think the challenge is how to use our collective experience from building the XML stack to create technologies that work natively with HTML, JSON and JavaScript, and that bring to the broader Web developer community some of the good aspects of the modern XML development experience.

Re: JSON5 Data Interchange Format

#69

Earlier quoted context omitted.

Getting over your pet peeves is a superpower.

Yeah exactly. That's why they should have stuck with just double quotes. Double quotes are far more popular than single quotes anyway.

How about sticking with JavaScript, as long as that's what the J and the S in JSON stand for. And as we all know, JavaScript supports both single and double quotes.

Or they could pull a YAML, and retroactively redefine what JSON stands for, the way YAML originally stood for "Yet Another Markup Language" until some party pooper pointed out to their great surprise that YAML was not actually a document markup language, but a data serialization language, so they redefined it to mean "YAML Ain't Markup Language" -- the opposite of what it originally meant.

https://en.wikipedia.org/wiki/YAML#History_and_name

https://en.wikipedia.org/wiki/Markup_language

Pro Tip: When naming you file format, look up what the words in your acronym mean, first.

Re: JSON5 Data Interchange Format

#70

Earlier quoted context omitted.

I want to love XML schemas, but to call them mature is a stretch. There's a bunch of important features hidden behind XSD 1.1, which is almost 10 years old by now, yet most software that validates XML on schemas does not support that yet.

The XML Schema standard is terrible, and its mistakes and weaknesses were what drove James Clark and Murata Makoto to develop RELAX NG (REgular LAnguage for XML Next Generation). https://en.wikipedia.org/wiki/RELAX_NG RELAX NG has a clearly focused sound mathematical underpinning: regular expressions applied to trees, while XML Schema is an ad-hoc hot mess designed by committee. https://en.wikipedia.org/wiki/XML_sche…

Interesting. I have validation of our internal (overly) complex configuration files on my todo list, and I'll have a look at using that, thanks!
Post reply on HN