Understanding the Internet Object — Part 1 — Transition from JSON to Internet Object

Mohamed Aamir Maniar
Internet Object
Published in
4 min readNov 5, 2019

Internet Object is an upcoming well-planned data serialization format for transmitting textual data over the internet. Its idea was originated out of the frustrations caused by JSON. However, soon it became an independent research project that aimed at developing the best data interchange format for the internet. This multipart series is designed to showcase the various aspects of Internet Object in a simple, direct and non-verbose fashion.

If you are not aware of the Internet Object, you can visit InternetObject.org or read the story here.

This article series assumes that you are well aware of the JSON document structure and its applications with respect to REST and API design and development.

To understand the Internet Object document, let’s starts with the JSON object. Most of the JSON objects are valid Internet Objects. Hence, the following JSON object is a valid Internet Object too.

{
"name": "Spiderman",
"age": 25,
"active": true,
"address": {
"street": "Queens",
"city": "New York",
"state": "NY"
},
"tags": ["agile", "emotional"]
}

However, it is not optimized for transfer over the wire! The idea is to trim down all the unnecessary stuff from the object so that it contains only the interchangeable/serializable/transferable data.

Spiderman, 25, T, {Bond Street, New York, NY}, [agile, swift]

Let’s start the transition by removing the quotations and the outer curly braces. Also, change the true to T.

name: Spiderman,
age: 25,
active: T,
address: {
street: Queens,
city: New York,
state: NY
},
tags: [agile, emotional]

The result is a valid keyed version of the Internet Object data document. To further optimize let’s move everything in the same line.

name: Spiderman, age: 25, active:T, address: {street: Queens, city: New York,  state: NY},tags: [agile, emotional]

Now separate out the keys from this object.

name, age, active, address: {street, city,  state}, tags

The result is a plain basic form of Internet Object schema. Though this is not the comprehensive and ideal version of the schema, it defines the object structure. After the schema is withdrawn away, the object is left with plain data.

Spiderman, 25, T, {Bond Street, New York, NY}, [agile, swift]

You can use schema and data independently (as defined above) or in their combined form as follows (separated by “data-separator” ---).

name, age:, active, address: {street, city, state}, tags
---
Spiderman, 25, T, {Bond Street, New York, NY}, [agile, swift]

This gives the fundamental structure of the Internet Object document. The way HTML document is divided into Head and Body, Internet Object document is divided into the Header and Data section. The header contains Schema and/or MetaData. We’ll see more about Meta Data in the next article in the series.

Serialization and Deserialization

Serialization and deserialization are easy and straight forward with InternetObject. The examples in this series will use JavaScript to showcase how to convert JavaScript objects into the InternetObject format and vice-versa. Other languages will have similar mechanisms for marshaling from the language-specific objects. As shown earlier, the InternetObject document can contain data and schema (full document) or only data. The following code showcases how to deserialize the full IO document.

Deserializing full IO document

const doc = String.raw`
name, age, active, address:{street, city, state}, tags
---
Spiderman, 25, T, {Bond Street, New York, NY}, [agile, emotional]`
// Deserialize into JavaScript object.
const io = new InternetObject(doc)
console.log(io.data) // Prints the JS object, see the output below

Deserializing IO data

This is the same case as the former, however, here schema and data is supplied independently in the InternetObject constructor.

const schema = String.raw`name, age, active, address:{street, city, state}, tags`const data = String.raw`Spiderman, 25, T, {Bond Street, New York, NY}, [agile, emotional]`// Load data and schema
const io = new InternetObject(data, schema)
console.log(io.data) // Prints the JS object, see the output below

However, when you log io.data both of the examples print the following JS object. InternetObject intelligently parses the raw IO data, merges with schema structure, validates them and produces the following object.

{
name: "Spiderman",
age: 25,
active: true,
address: {
street: "Queens",
city: "New York",
state: "NY"
},
tags: ["agile", "emotional"]
}

Serializing JavaScript object

To serialize the JavaScript object (Or any language-specific object for that matter) into the IO format, you need a schema. To serialize, load the object and schema into InternetObject and invoke the serialize() method.

const schema = String.raw`
name, age, address: {street, city, state}, active, tags`
const jsObject = {
name: "Spiderman",
age: 25,
active: true,
address: {
street: "Queens",
city: "New York",
state: "NY"
},
tags: ["agile", "emotional"]
}
const io = new InternetObject(jsObject, schema)
const ioData = io.serialize()
console.log(ioData)

It will generate the following result.

Spiderman,25,T,{Bond Street,New York,NY},[agile,emotional]

This article covered the basics of Internet Object including the transition from JSON to IO; it also summarized how the serialization with IneternetObject works. In the next article of the series sequel, we’ll see more about the structure of the InternetObject. So please stay tuned.

--

--

Mohamed Aamir Maniar
Internet Object

Aamir, as he prefers to be called, is a Founder & CEO of ManiarTech, Tallery Gallery. He loves technology, food, tea, flute, fitness & mobile photography