Explaining the usage advantages of json

For some time now, json has become a standard “protocol” that allows php and javascript to communicate between each other. (and the other way around). But what is json? from the site http://www.json.org :

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition – December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

But how to use it? There are different cases where to use json and a in a lot different ways. But one way (how I use json) is simple a communication platorm between php and javascipt and back. like this:

Let’s say we’ve got a webApp that needs to fetch data from a database. In this case, an ajax request will be preformed to a php page, php validates the request and fetches the data from the database. then php processes the data to json format and sends it back to the ajax call. Javascript processes this data and “paints” the html page with the given data. another representation:

The painter needs his paint to make a painting. In this case:

  • the paint = PHP processing
  • The painter = the json language
  • the brush = Javascript; who paints;
  • the painting = html page

Like I said, this is one of the usages of json.


subutux wrote 34 posts

Post navigation

Leave a Reply