JSON use cases

JSON stands for Javascript object notation. The data format is in human-readable text in key value pairs. Although it sounds like it will only work with javascript, but the good news is that it is language-independent, most programming languages have its parsers for reading and generating JSON data. Now we know what is JSON, but what do we do with it?

use case 1, store data in JSON files. This json is an array of objects, each object contains some information about a person.

[
{"name":"Amy", "age":21, "email":"amy@test.com"},
{"name":"Milanie", "age":25, "email":"milanie@test.com"}
]

use case 2, generating a json object from a form submitted by an user. Imagine someone went to you website and submitted a form in order to become a user of your website. When form is submitted, you will have the name, email and password, these can be temporary saved in memory in JSON format, and then use that json object to do other tasks such as saving the data in a database.

{"name":"Milanie", "email":"milanie@test.com", "pasword":"12345"}

use case 3, transferring data between systems. Imagine your website database has a person’s address information and you want to use an API service from Google to verify the address is valid. You can send the address data in JSON format to Google’s address validation service.

{
 "street": "2 broadway"
 "city": "New York"
 "zip": 11029
 "state": NY
}

use case 4, use json for configuration data. Assume you are developing a web application. When the application starts, it needs the credentials to connect to a database as well as a file path for wring logs. The credentials and the file path can be be specified in a json file, the json file will be read and be available for use when the database connection is needed or when wring logs.

{
  "database": {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "12345"
  },
  "files": {
    "log": "/log/app.log",
    "errorLog": "/log/error.log"
  }
}

There are tons of ways of using JSON, the above are only a few use cases.

Search within Codexpedia

Custom Search

Search the entire web

Custom Search