/lets-fix-json

Let's fix json

Apache License 2.0Apache-2.0

Let's fix json

JSON is everywhere. A lot of specs got better during the last years (tcp, http, JavaScript), but up to now the fundamental important data interchange format JSON has not changed much.

Why?

Roughly five years ago, in the year 2014 I thought: JSON is just a temporary solution. Its wide spread usage will decrease like XML. XML is mostly gone today. I thought Protocol Buffers is the future, since it supports more data types and is faster.

But the StackOveflow TagTrend makes it clear. JSON won't disapear and protobuf won't be widespread soon:

TagTrend JSON and alternatives:

TagTrend JSON and alternatives

This means we need to do upgrades in small steps.

Long term goal: pluggable data types

If the sender and the receiver agree upon some data types, it should be simple to add new data types to JSON.

Current step: Dream of fancy perfect future

How do we want JSON to be in the future?

Before consensus can be reached, the dream need to be written down.

Later

??? up to now it is unclear how to update the specs. But I guess we will find a way.

Feedback needed

Please tell me what you think:

  • What do you want to add to JSON?
  • Why do you prefer a different a different data format? Why do you think other formats are better?

Let's influence the future together :-)

Please create a new issue and tell us how you would like JSON to look like in the future: https://github.com/guettli/lets-fix-json/issues/new

add binary data type

There thousand ways to work around it. Very common is base64 encoding. But that's a useless work-around.

In Python you can create binary data with the "b" prefix. Example:

binary_data = b'\x00\xff....'

add datetime

It would be nice to support it.

Other tools which support this:

Soon you can parse datetimes in JavaScript like this: Temporal.DateTime.from("2019-11-26T14:58:54.147Z").

But I want more. I don't want to parse strings and convert them to an object over and over again. I want to parse a JSON string and get nice high level DateTime objects immediately.

Proposed syntax: String prefix "dt": dt"1985-04-12T23:20:50.52Z"

add timedelta

A timedelta datatype would be very nice.

Other tools which support this:

add comments

Quoting @asb:

Leave comments is essential for human beings understand what is going up. Is the best practice in any programming language. Is kind and nice for all who will study what is done. Every one knows that JSON was, -was- a encapsuled internal way to exchange data in javascript but now JSON is used do describe the data for all world. So, please make // into comments for JSON, let the spice flow.

Why HCL (HashiCorp Configuration Language) was invented:

JSON ... is fairly verbose and most importantly doesn't support comments.

Source: https://github.com/hashicorp/hcl

add pointers

... some provision for internal object pointers, to allow non-tree data structures to be encoded ...

Chip Morningstar Dec 2019 at TC39 Discussion

add unquotes strings

Up to strings need to be quoted strings.

{"foo": "bar"}

For simple strings (without whitespaces or special characters) quoting is not necessary. This makes it simpler to write config in JSON by hand:

{foo: bar}

Alternatives

There are several alternatives to JSON. I think it makes more sense to upgrade JSON, than to use an alternative

  • Protocol Buffers supports above feature, except comments. The major drawback that you are forced to define your data in a IDL (interface definition language). Second draw back: it is binary
  • BSON Draw back: it is binary. It does not support timedelta.

Related

Thanks