Understanding the JSON Document Model

The JSON Document Model is a standard that allows for lightweight data-interchange, and that makes it easy for developers to read and change information across applications. JSON documents are flexible and you can use querying and indexing with them. They provide a clear, logical structure that makes it possible to handle more complex data, and they enable you to provide logical connections between records.

There are many basic data types supported with JSON, including:

– Integers and floating-point numbers
– Strings (with escape characters, and Unicode)
– BOOL
– Arrays
– Objects in the form of key-value pairs, that are made up of strings

Making use of the JSON document model is good for getting you to think about the data that your application uses, and how it fits into different groups. You need to think about the information that you want to manage within your application, and how to build logical containers for it. In some ways it is similar to how you would model for a relational database, but there is a lot more flexibility, so you can change your mind later if you need different data structures. This is a huge benefit.

Planning Your JSON Document

You should consider the following when planning a JSON document:

– What ‘things’ the document needs to hold
– How you want to store information about them
– The groups the things fit into

So, for example, if you run a martial arts studio and you want to store information about your students and the number of classes they went to, then a student might have the following:

{ “name”: “age” : “belt”: “idnumber” }

You could record information about each class in this form:

{ “classnumber”: “date”: “venue”: “classtheme” }

It’s also possible to nest information, for example, instead of venue you could use the JSON tag for the location with lat, long coordinates. This can then be pulled straight out of the document to plot it onto the map.

JSON documents can be parsed through database systems, or just read in a similar way to XML using a parser, depending on the size of the document, the language you are using, and hteir intended use.

JSON Versus RDBMS

If you’re used to relational databases, then you will be familiar with the idea of normalizing the data, maintaining separate documents and then linking the data using keys. This is something that you can do with a JSON document if you wish, or you can use a nested approach instead, with a single document representing each ‘thing’ instead.

Deciding when to use nested objects and when to use separate documents is something that takes experience. Making the wrong decision can greatly impair performance. However, since JSON gives developers the flexibility to use either option, this means that in some cases it can offer far better performance than a relational database. In addition, while you plan your documents and data structures, you will be forced to think about them in a way that helps you to develop a far more robust application.