Really Relaxed JSON

json data format October 4, 2021

JSON is a common lingua franca for interaction between processes, because it’s so easy to type and use, and apparently XML is terrible (it’s not, but hey!). But JSON is sometimes not all that easy to work with, either.

Here’s an example JSON message:

{ 
  "type": "message",
  "content": "But I don't see how that makes any sense!"
}

RJSON relaxes the need for some of the quotes. We can convert input like this:

{
  type: message,
  content: "But I don't see how that makes any sense!"
}

Note the lack of quotes around some of the field names and values. It’s a small convenience, but it adds up.

There’s a library for Javascript and the JVM, called really-relaxed-json, that allows you to convert RJSON to JSON.

In JavaScript it’s a trivial install:

npm i really-relaxed-json

In Java, it’s a simple Maven (or Gradle) dependency, but requires adding the Sonatype repositories. The dependency content looks like this:

<dependencies>
  <dependency>
    <groupId>tv.twelvetone.rjson</groupId>
    <artifactId>rjson</artifactId>
    <version>[1.3.0-SNAPSHOT,)</version>
  </dependency>
  <dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib-jdk8</artifactId>
    <version>${kotlin.version}</version>
  </dependency>
<dependencies>

The repositories node would need this:

<repositories>
  <repository>
    <id>sonatype-nexus-snapshots</id>
    <name>Sonatype Nexus Snapshots</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>

Note that really-relaxed-json needs the Kotlin runtime library; it’s not (currently) listed as a transitive dependency in the library itself. (An issue has been filed to correct this.)

in json javascript java kotlin data format

Reading time: 1 minute.