Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex JSON and Tutorials

Can anyone show me some complex JSON structure and tutorials where i can excel more on this JSON topic using javascript. So far i am able to understand JSON, its basic structure and how to parse and alert out properties.

I can search in google or other search engines, but i want links from you expert guys who can lead me to right direction than a BOT which displays result.

like image 388
John Cooper Avatar asked May 27 '11 22:05

John Cooper


People also ask

What is complex JSON?

Complex JSON objects are those objects that contain a nested object inside the other. Example of Complex JSON Object.

Is JSON a complex data type?

At the granular level, JSON consists of 6 data types. The first four data types (string, number, boolean and null) can be referred to as simple data types. The other two data types (object and array) can be referred to as complex data types.

How difficult is JSON?

JSON is easier to use than XML and human readable. Most modern web APIs output data in JSON formats. It's a lightweight data interchange format that is quickly becoming the default format for data exchange on internet today! JSON is lightweight, language independent and easy to read and write.

How many types of JSON are there?

JSON defines seven value types: string, number, object, array, true, false, and null. The following example shows JSON data for a sample object that contains name-value pairs.


2 Answers

Basics

  • Read everything on json.org, including:
    • the code for the standard json2.js,
    • and this page explaining the standard JavaScript JSON.* APIs
    • (Skip the formal definitions for now, and get back to it regularly)
  • Read the corresponding JSON Wikipedia entry
  • Read the Mozilla Developer Docs' JavaScript Reference on:
    • JSON, the JSON object, JSON.parse and JSON.stringify
    • Using native JSON
  • Read blogs and articles:
    • Get Started with JSON
    • JSON: What is is, how it works, how to use it
  • Read slides:
    • Replacing XML with JSON
    • Advanced JSON
    • The JSON saga (Also by Douglas Crockford, creator of JSON and json.org, ECMAScript committee member, and acclaimed writer - see below)
  • Even watch some videos
  • Get to know ECMAScript/JavaScript better:
    • Crockford's essays on JavaScript
    • the ECMAScript ECMA-262 standard, 5th edition
    • Crockford's book JavaScript: the Good Parts
  • Browse StackOverflow:
    • questions on JSON
    • questions on Advanced JSON
    • and also questions on Advanced JavaScript to polish your skills

Get (a lot) more involved...

Check out JSON processors and libraries

If you have some knowledge of other languages, you could look at some JSON processors' implementations and get to know what makes them better or worse than their competitors, read their code, etc...

For instance, for Java:

  • json-lib
  • Jackson
  • google-gson
  • FlexJSON

For other languages: see json.org (at the bottom of the page) for tons of links.

Learn about JSON variants and JSON-based concepts

  • JSONP Wikipedia Entry
  • BSON Wikipedia Entry
  • ...

Experiment with some JSON endpoints

Look online for webservices exposing JSON-enabled endpoints to play with them. Head over to ProgrammableWeb for that, or use any search engine.

For experimenting, use either:

  • Google Chrome and open the Chrome Dev Tools (CTRL+SHIFT+J),
  • Firefox and install and open Firebug (F12),
  • Internet Explorer and open the Debug Tools (F12) (or install Firebug Lite),
  • Alternatively:
    • Google Code Playground to play with some of their services (specifically, try that example for an easy JSONP demo with jQuery),
    • jsFiddle lets you experiment with libraries and share snippets.

Actually you could very much just use your javascript console to experiment without any end-point and test whether you manage to create objects.

like image 188
14 revs Avatar answered Sep 22 '22 23:09

14 revs


JSON has following types of elements:

  • objects (eg. {} or { something: 'somevalue' }, JSON itself),
  • arrays (eg. [] or [1, 'test', false, true, false, 1, 22, 33]),
  • boolean (true or false),
  • integers (eg. 0, 10, -23342),
  • floats (eg. 0.2, 3.1415, -321312.01),
  • null,

So to construct some complicated JSON you can just combine all of the above and assign it to some variable:

var myjson = {
    myame: 'Tadeck',
    myinterests: [
        'programming',
        'games',
        'artificial intelligence',
        'business models'
    ],
    mydata: {
        'age': 'not your business',
        'something': 'das',
        'friends': [
            'A',
            'B',
            'C'
        ]
    },
    facebook_friends_count: 0,
    iq: 74.5,
    answered_your_question: true,
    answer_sufficient: null,
    question_can_be_answered_better: false,
    solutions: [
        'read about JSON',
        'test JSON in JavaScript',
        'maybe test JSON in different languages',
        'learn how to encode some special characters in JSON'
    ]
}

Then play with it in JavaScript and remember that this is the way objects are noted in JavaScript. This is simple, yet very powerful solution (used eg. by Twitter).

If this will not help (btw. again: visit JSON.org), I have one more advice for you: practice.

like image 35
Tadeck Avatar answered Sep 19 '22 23:09

Tadeck