Skip to main content

working with JSON

JavaScript Object Notation is a schema-less, text-based representation of structured data, based on key-value pairs. JSON is derived from JavaScript and commonly, but not exclusively, used to exchange information between web clients and web servers through APIs.. 
Today JSON is the format of choice for almost every web service.
Relational databases like PostgreSQL and MySQL now support for storing and querying JSON data. NoSQL databases like MongoDB and Neo4j also support JSON.
Below I'll take a quick look at JSON. Let’s start with an example: 
{
  “firstName”: “Asiri”,
  “lastName”: “Hewage”,
  “loginCount”: 1,
  “isOnline”: true,
  “worksWith”: [“Pearson”, “Intern”],
  “pets”: [
    {
      “name”: “Kalu”,
      “type”: “Dog”
    }
  ]
}
Above structure clearly defines some attributes of an entity. It includes a first and last name ...etc. The structure may be passed from a server to a web browser or a mobile application, which will then perform some action such as displaying/saving it for later reference.
JSON value typesstrings, numbers, booleans, lists, objects, and null. 

npm Installation

Using npm :

  1. Get node.
  2. npm install -g json
Manual method:
  1. Get the 'json' script. Then put it on your PATH somewhere (it is a single file with no external dependencies). Ex:
     cd ~/bin
     curl -L https://github.com/trentm/json/raw/master/lib/json.js > json
     chmod 755 json
    
Then check "json" on your PATH:
$ json --version
json 9.0.0
Why should I use JSON? 
The data was transferred in XML format in old applications, and XML was verbose and difficult to manage in JavaScript. JavaScript already had objects, which are a way of expressing data within the language. JSON was much easier for people to read and for browsers to parse. Soon web developers began to prefer JSON over XML.
Now JSON is the standard for exchanging data between web and mobile clients and back-end services. 

When should I use JSON?

  • If you’re writing software that communicates with a browser or native mobile application, you should use JSON as the data format. 
  • In the case of server-to-server communication JSON isn’t a bad choice.
  • If you’re using NoSQL databases, you’re pretty much stuck with whatever the database gives you. In relational databases that support JSON as a type, a good rule of thumb is to use it as little as possible. 
  • You can expect a performance hit when querying for properties within those JSON objects.
  • Its simple design and flexibility make it easy to read and understand, and in most cases, easy to manipulate in the programming language of your choice. 
  • The lack of a strict schema enables flexibility of the format, but that flexibility sometimes makes it difficult to ensure that you’re reading and writing JSON properly.
  • Choosing XML over JSON when building a new web service is a red flag likely to turn away talent, because it indicates a lack of interested in staying relevant. 

Limits of JSON

Here are the five main limitations: 
  1. No schema. 
  2. Only one number type.
  3. No date type. 
  4. No comments. 
  5. Verbosity. 

Comments

Popular posts from this blog

Introducing props

React alloıs us to send data to a component in the same syntax as HTML, using attributes or properties on a component. This is akin to passing the src attribute to an image tag. We can think about the property of the  < img /> tag as a prop we're setting on a component called img . We can access these properties inside a component as this.props . Let's see props in action. Recall, we defined the  < Header /> component as:   When we use the < Header /> component, we placed it in our component as like so: We can pass in our title as a prop as an attribute on the < Header / > by updating the usage of the component setting the attribute called title to some string, like so:  Inside of our component, we can access this title prop from the this.props property in the Header class. Instead of setting the title statically as Timeline in the template, we can replace it with the property passed in.  Now our  < Header />  compone

Science Animated - Chemistry, Physics Experiments On Android Mobile

  " Science Animated " is an educational app that will allow you to conduct physics and chemistry experiments in an easy and really entertaining way within your classroom and beyond. With "Science Animated", you will be able to create engaging experiments utilizing the accelerator, the pH scale and other scientific instruments. You will also find pre-designed educational games that have been especially created for you! "Science Animated" is transforming physics and chemistry from theoretically intense to intensely fun!   ############## Features ############## * Earn more points while you learn. * Use your points to activate all premium content for free. * Share and redeem points. * Login with google to save your points and use across all Asia Cloud Apps. ################ Labs ############### * pH Scale * pH Scale: Basics * Arithmetic * Molecular shapes * Shapes of the molecules: basic points * Acid solvents * Light reflex * Oh's law * Resistance of wir

GIT & GitHub A to Z

Concept of Version Controlling.  Version control  is a system that records changes to a file or set of files over time. Then you can recall specific  versions  later. For the examples in this blog, you will use my source code on GitHub as the files being  version  controlled. There are three types of Version Control Systems. 1. Local Version Control System ( maintains track of files within the local system ) 2. Centralized Version Control System (   files are tracked under the centralized server ) 3. Distributed Version Control System ( clients completely clone the repository including its full history ) Those version control systems are  broken down into two main categories,  centralized  and  decentralized  ( distributed ). The GIT terminology Most version control systems involve the following concepts. Popular Version Control Systems: SVN:  https://subversion.apache.org/ Git:  https://git-scm.com/ Mercurial:  https://www.mercurial-scm.org/