JSON Crash Course




In this video we will talk about JSON, JavaScript object literals and AJAX. Ill show you how to create JSON objects and arrays and also how to make an Ajax request to a .json file

CODE: Code for this video
http://traversymedia.com/downloads/json_sandbox.zip

EDUONIX COURSES: Please use affiliate links from website below
http://www.traversymedia.com/eduonix-courses

SUPPORT: We spend massive amounts of time creating these free videos, please donate to show your support:
http://www.paypal.me/traversymedia
http://www.patreon.com/traversymedia

FOLLOW TRAVERSY MEDIA:
http://www.facebook.com/traversymedia

http://www.linkedin.com/bradtraversy

Original source


31 responses to “JSON Crash Course”

  1. Great Video. Thanks. Here you are using node.js and accessing the file from cmd. Is there a simpler way so that I can double click on the index.html file and see the output like an average user on chrome/firefox rather than accessing from cmd. If anybody could mention it would be a big help…

  2. Let's say I'm using JSON files as a read-only data store of sorts. I have several MB of data that I don't want to pass over the wire all at once unless needed. I have it parsed into ~100 subdivisions of a few KB to a MB. I can have a one-page .js app pull data from these files (actually pull all the data from one whole file at a time, as demanded) based on query string and a few short look-up structures in the one page to translate the request.

    Bottom line, I've got a bunch of json files. I want them to be as short as possible. I like that I can address the data when I read it in with names for the indices, like file1.person.lastname, say. But, I sure as hell don't want to write "lastname": "Smith" 500 times in the file. That wastes bandwidth. Is there a way to define a type, then instantiate it 1000 times (like in an array of that type) in the same json file without the label, but simply by order, so I can save potentially tens of KB of transmission while still using the intuitive class member naming scheme in my one page (instead of using numeric indices as I fear I might have to)? I hope this is an intuitive question and I just don't know something I should but that is never covered in tutorials.

  3. <body>

    <main>

    </main>

    <script>

    let renderOrderedList = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon"];

    let output = ' ';

    for (let i = 0; i < renderOrderedList.length; i++) {

    output += '<ol>' +

    '<li>' + renderOrderedList[i] + '</li>' +

    '</ol>';

    }

    document.querySelector('main').innerHTML = output;

    </script>

    </body>

    I have above code which is working properly but when I try to use the function it wont work. Can anyone help me to solve the below code if possible?

    function renderOrderedList(){

    let output = ' ';

    for (let i = 0; i < renderOrderedList.length; i++) {

    output += '<ol>' +

    '<li>' + renderOrderedList[i] + '</li>' +

    '</ol>';

    }

    document.querySelector('main').innerHTML = output;

    }

    renderOrderedList(["Alpha", "Beta", "Gamma", "Delta", "Epsilon"]);

Leave a Reply