Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • JavaScript JSON

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 111
    Comment on it

    JSON stands for JavaScript Object Notation which is a format for storing data.
    JSON is used when we have to send data from server to webpage.

    JSON Example

    {
    "employees":[
        {"firstName":"Pranav", "lastName":"Chhabra"}, 
        {"firstName":"Mukesh",    "lastName":"Tomar"},
        {"firstName":"Sachin", "lastName":"Joshi"}
    ]
    }
    

    JSON data is written as name/value pairs

    A name/value pair is made up of a field name in double quotes, followed by a colon, followed by a value:

    "firstName":"Pranav"
    

    Example

    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>Create Object from JSON String</h2>
    
    <p id="demo"></p>
    
    <script>
    var text = '{ "employees":[
        {"firstName":"Pranav", "lastName":"Chhabra"}, 
        {"firstName":"Mukesh",    "lastName":"Tomar"},
        {"firstName":"Sachin", "lastName":"Joshi"}
    ]}
    obj = JSON.parse(text);
    document.getElementById("demo").innerHTML =
    obj.employees[1].firstName + " " + obj.employees[1].lastName;
    </script>
    
    </body>
    </html>
    

    OUTPUT
    Create Object from JSON String

    Mukesh Tomar

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: