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

Express Js - එක්ස්ප්‍රස් js වලින් වැඩ ගනිමු

යළුවනේ, අද ම්ං මේ කියන්න යන්නේ තවත් JavaScript Library එකක් ගැන. ඒ Express JS. මේක Node.Js වලටම හදපු Web Framework එකක්. Express කියන්නේ වෙබ් සහ ජංගම යෙදීම් සඳහා ශක්තිමත් විශේෂාංගයක් සපයන අවම හා නම්‍යශීලී Node.js Web Framework එකක්. (වෙබ් යෙදුම් රාමුවක්).
මේ Framework එකෙන් පරිශීලක අතුරු මුහුනතයි (User Interface) එකයි Back End එකයි එකතු කරන්න API (Application Programming Interface) එකක් හදාගන්න පුළුවන්. ඒ කියන්නේ අපි හදන වෙබ් ඇප්ලිකේශන් (Web Application) එකේ පරිශීලකයාට පෙනෙන UI එකයි Server එකේ තියෙන ප්‍රධානම බිස්නස් ලොජික් (Business Logic) එකයි සම්බන්ධ කරන්න පුලුවන් මේ Framework එකෙන්.

Node JS : npm පාවිච්චි කරල හරිම පහසුවෙන් අපේ project එකට එකතු කරගන්න පුළුවන්. Project path එකේ console එකක් අරන් එකේ මේ code එක execute කරන්න මුළින්ම. මේකෙන් project එකට අවශ්‍ය Express node module එක ඔයාගේ project root එකේ node-modules එකට එකතු කරනවා.


$ npm install express --save
දැන් ඔයගේ ප්‍රොජෙක්ට් එකට Express dependencies එකතු වෙලා තියෙන්නේ. දැන් app එකක් හදන්න මෙන්න මේ විදිහට server.js කියල file එකක…

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/Repository: The database.Changelog: A list of changes made.Syncing: Synchroni…