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 එකක් හදන්න මෙන්න මේ විදිහ...

GitHub පාවිච්චි කරලා කරන්න පුළුවන් දේවල් මොනවද?

GitHub පාවිච්චි කරන ප්‍රධානම දේ තමයි Coding. තමන්ගේ Code එකක් පරෙස්සමට තියාගන්න හුගක් අය Github පාවිච්චි කරනවා. තව Documentation කරන්න තියෙන පහසුව. ඔබ දැකල තියෙනවනම් repository එකක් create කරද්දී අපිට README file එකත් හදාගන්න පුළුවන්. මේකේ මුළු project එකටම අදාලව files තියෙන විදිහ දක්වන්න README file එක පාවිච්චි කරනවා.  තවත් වැදගත් දෙයක් තමයි Issue Tracking කරන්න Github පාවිච්චි කරනවා. Commits History එක maintain කරන්න Github පාවිච්චි වෙනවා. Commits කියන්නේ මොනාද කියල ප්‍රශ්නයක් ආවනම් අපි ඒ ගැන ඉස්සරහට කතා කරමු. pulse, contributors, commits, code frequency, punch card, network, members වගේ ප්‍රධාන සාධක ගණනාවක් මේ Project එකකට බලපානවා. මේවා ගැන graphs ලබාගන්න පුළුවන්.  Email Notifications කෙනෙක්ව mention කිරීමේ හැකියාව Emojis එකතු කිරීම https://username.github.io  යන ආකාරයේ කුඩා websites host කිරීමේ හැකියාව Common Vulnerabilities  වලදී Security Alert එකක් ලැබීම  වගේ දේවල් මේකේ අන්තර්ගත වෙනවා. මේ තමයි Github web interface එක.  ...

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...