Take the 2-minute tour ×

Ok, So I'm using AJAX to pull some information from my MYSQL database and put it onto the screen. The thing is I cannot understand JSON for the life of me. Can you suggest any tutorials or anything that will help?

I mean I get that I can encode my query via JSON but I guess it's the javascript side I do not understand.

share|improve this question

5 Answers 5

up vote 1 down vote accepted

Here's my quick tutorial:

JSON is a means for expressing data for arrays, objects, and their contents. It has nothing to do with object behaviour (methods).

class Test {
    public $hello = 'hello';
    public $something = array('hello1', 'hello2');

    public __construct() {


    public void printHello() {
        echo $this->hello;

This class would in JSON would look like:

var obj = {
   "hello": "hello",
   "something": ["hello1", "hello2"] 

As you can see, JSON is similar to maps in a lot of languages (key/value pairs). You can also see, that only data is represented. JSON is also shorthand for JavaScript builtins. For example, this previous object can be written in JavaScript like so.

   var obj = new Object();
   obj.hello = "hello";
   obj.something = new Array("hello1", "hello2");

Hope this gives you a little idea of what JSON is about.

share|improve this answer
But how would you pull those values once their in JSON? print(obj[0]); ? –  Howdy_McGee Jul 3 '11 at 22:59
I'm not following. Are you asking how to get those values back into php objects? –  marchaos Jul 3 '11 at 23:20
oh no sorry, not pull. I mean print the values to HTML or anything. –  Howdy_McGee Jul 3 '11 at 23:29

First, read this: http://www.json.org/js.html

Then, practice with this: http://jsonlint.com/

share|improve this answer

You can read about using JSON in JavaScript at the Mozilla docs.

share|improve this answer

How to use JSON (updated with example)


share|improve this answer
Thanks but that's the JQuery version, i barely understand AJAX(JQuery) as it is. –  Howdy_McGee Jul 3 '11 at 23:01

Your Answer


