JSON (JavaScript Object Notation) is a popular lightweight data-interchange format, based on the object-literal notation of JavaScript. It is programming-language neutral but uses conventions from various languages. Easy for humans to read and write, and easy for machines to parse and generate, JSON is a widely used data exchange format. And is easier to work with than XML (less writing of parsers), which doesn’t quite fill the bill as a language for structured data.

JSON Logo

 

JSON is a great way to talk across languages and handle structured data. In addition, using a JSON document is a good mechanism for managing document-oriented information (also known as semi-structured data). Document-oriented databases, such as JSON documents, comprise one of the main categories of NoSQL databases, which have many practical applications.

So, when talking about the kind of values that JSON document supports…it’s essentially a format that works across multiple programming languages and has the flexibility to handle semi-structured data. Because of these factors, most requests and responses to and from Apache CouchDB (and IBM Cloudant) use JSON for formatting the content and structure of the data and responses. In Cloudant databases, the JSON object represents various structures, including all documents in a database.

Creating a database and adding documents is simple. See how to do it here.

JSON works as a simple and neat solution to manipulate data using a web browser, because its structures can be evaluated and used as JavaScript objects within the web browser environment. It also integrates with the server-side JavaScript used within Cloudant. UTF-8 encoding applies to all JSON documents.

As mentioned earlier because it is the object notification for JavaScript, a JSON document supports all of the same basic values as JavaScript.

Supported JSON Values 

Supports the same basic types as supported by JavaScript:

Numbers

The Number JavaScript object is a wrapper object, allowing you to work with numerical values. A Number object is created using the Number() constructor.

Example uses:
• If the argument cannot be converted into a number, it returns NaN.
• In a non-constructor context (i.e., without the new operator), Number can be used to perform a type conversion.

Strings

Strings hold data that can be represented in text form. A double quotation mark should enclose all strings. Strings support Unicode characters and backslash escaping.

Example uses:
• Checking the length or number of units in a string.
• Build and concatenate strings using the + and += string operators,
• Check for the existence or location of substrings with the indexOf() method,
• Extracting substrings with the substring() method.

Booleans

Boolean returns a true or false value. You can use the Boolean() function to find out whether an expression (or a variable) is true.

Arrays

A list of bracketed values. The enclosed values can contain any valid JSON. They are single objects that store multiple values in a list. In JSON, array values must be of type string, number, object, array, Boolean or null.

Example use:
• Loop through an array and perform the same thing to every value within the array

Objects

A set of key/value pairs, such as an associative array, or a hash. The key must be a string, but the value can be any of the supported values.

Example use:
• Compare if two values are the same value.

Start working with document stores today. Sign up for a free 30-day trial of Cloudant, IBM’s managed NoSQL database service, part of the Watson Data Platform.

 

Learn more about Cloudant and NoSQL database technology

Join The Discussion

Your email address will not be published. Required fields are marked *