//By using jquery json parser    
var obj = $.parseJSON('{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}');
alert(obj['jobtitel']);

//By using javasript json parser
var t = JSON.parse('{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}');
alert(t['jobtitel'])

Check this jsfiddle

As of jQuery 3.0, $.parseJSON is deprecated. To parse JSON strings use the native JSON.parse method instead.

Source: http://api.jquery.com/jquery.parsejson/

Answer from sawan on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_objects.asp
JSON Object Literals
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... JSON object literals are surrounded by curly braces {}. JSON object literals contains key/value pairs.
๐ŸŒ
I'd Rather Be Writing
idratherbewriting.com โ€บ learnapidoc โ€บ docapis_access_json_values.html
Access and print a specific JSON value | I'd Rather Be Writing Blog and API doc course
1 week ago - While objects allow you to get a specific property, arrays require you to select the position in the list that you want. ... <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <title>Sample Page</title> <script> var settings = { "async": true, "crossDomain": true, "url": "https://api.openweathermap.org/data/2.5/weather?zip=95050&appid=APIKEY&units=imperial", "method": "GET" } $.ajax(settings).done(function (response) { console.log(response); var content = response.wind.speed; $("#windSpeed").append(content); var currentWeather = response.weather[0].main; $("#currentWeather").append(currentWeather); }); </script> </head> <body> <h1>Sample Page</h1> <div id="windSpeed">Wind speed: </div> <div id="currentWeather">Current weather conditions: </div> </body> </html>
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-get-a-value-from-a-json-array-in-javascript
How to Get a Value from a JSON Array in JavaScript? - GeeksforGeeks
June 28, 2025 - JS Tutorial ยท Web Tutorial ยท ... array in JavaScript, we can use various methods such as accessing the array by index or using built-in methods like find(), map(), etc....
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ JSON โ€บ parse
JSON.parse() - JavaScript - MDN Web Docs
The JSON.parse() static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
๐ŸŒ
Thequantizer
thequantizer.com โ€บ the quantizer โ€บ javascript
JavaScript: How to Get JSON value by Key :: The Quantizer
so finally to get the value of price we can do the following ยท let firstKey = Object.keys(firstObj)[0]; let firstKeyValue = firstObj[firstKey]; will return ยท 13300000 ยท If we wanted preform operations on all the elements in the array we have a few ways to do this. One of the most common is a forEach loop. jsonData.forEach((element, i) => { console.log("element: " + i + " is: " + JSON.stringify(element)) }); jsonData = JS object ยท
๐ŸŒ
ServiceNow Community
servicenow.com โ€บ community โ€บ developer-blog โ€บ fetch-value-from-json โ€บ ba-p โ€บ 2282127
Fetch value from JSON - ServiceNow Community
July 13, 2023 - Use the JSON.stringify() method to convert object/array into string to send it further processing. I will keep updating the content with different scenarios as and when I get more experience in this subject to share also as per your valuable feedback and suggestions.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ javascript โ€บ get value from jason object in javascript
How to Get Value From JSON Object in JavaScript | Delft Stack
February 2, 2024 - There can be multiple practices to access JSON object and array in JavaScript by the JSON.parse() method. Either it can be accessed with a dot(.) operation or by a bracket pair([]).
Find elsewhere
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ javascript โ€บ how to access json object in javascript
How to access JSON object in JavaScript - Mkyong.com
October 12, 2013 - To access the JSON object in JavaScript, parse it with JSON.parse(), and access it via โ€œ.โ€ or โ€œ[]โ€.
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ javascript-tutorial โ€บ javascript-json-parsing.php
JavaScript JSON Parsing - Tutorial Republic
Let's suppose we've received the following JSON-encoded string from a web server: ... Now, we can simply use the JavaScript JSON.parse() method to convert this JSON string into a JavaScript object and access individual values using the dot notation ...
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_parse.asp
JSON.parse()
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object. ... Make sure the text is in JSON format, or else you will get a syntax error.
Top answer
1 of 4
154

There are two ways to access properties of objects:

var obj = {a: 'foo', b: 'bar'};

obj.a //foo
obj['b'] //bar

Or, if you need to dynamically do it:

var key = 'b';
obj[key] //bar

If you don't already have it as an object, you'll need to convert it.

For a more complex example, let's assume you have an array of objects that represent users:

var users = [{name: 'Corbin', age: 20, favoriteFoods: ['ice cream', 'pizza']},
             {name: 'John', age: 25, favoriteFoods: ['ice cream', 'skittle']}];

To access the age property of the second user, you would use users[1].age. To access the second "favoriteFood" of the first user, you'd use users[0].favoriteFoods[2].

Another example: obj[2].key[3]["some key"]

That would access the 3rd element of an array named 2. Then, it would access 'key' in that array, go to the third element of that, and then access the property name some key.


As Amadan noted, it might be worth also discussing how to loop over different structures.

To loop over an array, you can use a simple for loop:

var arr = ['a', 'b', 'c'],
    i;
for (i = 0; i < arr.length; ++i) {
    console.log(arr[i]);
}

To loop over an object is a bit more complicated. In the case that you're absolutely positive that the object is a plain object, you can use a plain for (x in obj) { } loop, but it's a lot safer to add in a hasOwnProperty check. This is necessary in situations where you cannot verify that the object does not have inherited properties. (It also future proofs the code a bit.)

var user = {name: 'Corbin', age: 20, location: 'USA'},
    key;

for (key in user) {
    if (user.hasOwnProperty(key)) {
        console.log(key + " = " + user[key]);
    }
}    

(Note that I've assumed whatever JS implementation you're using has console.log. If not, you could use alert or some kind of DOM manipulation instead.)

2 of 4
21

Try the JSON Parser by Douglas Crockford at github. You can then simply create a JSON object out of your String variable as shown below:

var JSONText = '{"c":{"a":[{"name":"cable - black","value":2},{"name":"case","value":2}]},"o":{"v":[{"name":"over the ear headphones - white/purple","value":1}]},"l":{"e":[{"name":"lens cleaner","value":1}]},"h":{"d":[{"name":"hdmi cable","value":1},{"name":"hdtv essentials (hdtv cable setup)","value":1},{"name":"hd dvd \u0026 blue-ray disc lens cleaner","value":1}]}'

var JSONObject = JSON.parse(JSONText);
var c = JSONObject["c"];
var o = JSONObject["o"];
๐ŸŒ
ServiceNow Community
servicenow.com โ€บ community โ€บ developer-forum โ€บ unable-to-fetch-the-key-value-for-json-parsed-in-javascript โ€บ m-p โ€บ 2365918
Unable to fetch the key value for JSON parsed in Javascript getting undefined message
October 29, 2022 - var jsonobject = { "budget": "value", "jobid": "value", "location": "value", "plbs": "value" }; var test = JSON.stringify(jsonobject); var parsed = JSON.parse(test); gs.info("budget: " + parsed.budget); gs.info("jobid: " + parsed.jobid); gs.info("location: " + parsed.budget); gs.info("plbs: " + parsed.budget); ... same issue I am getting same output : "undefined" for location , jobid and plbs values .
Top answer
1 of 6
48

JSON content is basically represented as an associative array in JavaScript. You just need to loop over them to either read the key or the value:

    var JSON_Obj = { "one":1, "two":2, "three":3, "four":4, "five":5 };

    // Read key
    for (var key in JSON_Obj) {
       console.log(key);
       console.log(JSON_Obj[key]);
   }
2 of 6
19

First off, you're not dealing with a "JSON object." You're dealing with a JavaScript object. JSON is a textual notation, but if your example code works ([0].amount), you've already deserialized that notation into a JavaScript object graph. (What you've quoted isn't valid JSON at all; in JSON, the keys must be in double quotes. What you've quoted is a JavaScript object literal, which is a superset of JSON.)

Here, length of this array is 2.

No, it's 3.

So, i need to get the name (like amount or job... totally four name) and also to count how many names are there?

If you're using an environment that has full ECMAScript5 support, you can use Object.keys (spec | MDN) to get the enumerable keys for one of the objects as an array. If not (or if you just want to loop through them rather than getting an array of them), you can use for..in:

var entry;
var name;
entry = array[0];
for (name in entry) {
    // here, `name` will be "amount", "job", "month", then "year" (in no defined order)
}

Full working example:

(function() {
  
  var array = [
    {
      amount: 12185,
      job: "GAPA",
      month: "JANUARY",
      year: "2010"
    },
    {
      amount: 147421,
      job: "GAPA",
      month: "MAY",
      year: "2010"
    },
    {
      amount: 2347,
      job: "GAPA",
      month: "AUGUST",
      year: "2010"
    }
  ];
  
  var entry;
  var name;
  var count;
  
  entry = array[0];
  
  display("Keys for entry 0:");
  count = 0;
  for (name in entry) {
    display(name);
    ++count;
  }
  display("Total enumerable keys: " + count);

  // === Basic utility functions
  
  function display(msg) {
    var p = document.createElement('p');
    p.innerHTML = msg;
    document.body.appendChild(p);
  }
  
})();

Since you're dealing with raw objects, the above for..in loop is fine (unless someone has committed the sin of mucking about with Object.prototype, but let's assume not). But if the object you want the keys from may also inherit enumerable properties from its prototype, you can restrict the loop to only the object's own keys (and not the keys of its prototype) by adding a hasOwnProperty call in there:

for (name in entry) {
  if (entry.hasOwnProperty(name)) {
    display(name);
    ++count;
  }
}
๐ŸŒ
Medium
jwwnz.medium.com โ€บ accessing-json-values-using-variables-fd5fe00161c
Accessing JSON values using variables | by JW | Medium
February 25, 2021 - Accessing JSON values using variables Some simple options for accessing JSON values with dynamic keys. Usually when accessing JSON you would access the value as follows. object.keyName But you can โ€ฆ
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-work-with-json-in-javascript
How To Work with JSON in JavaScript | DigitalOcean
August 26, 2021 - This will look very familiar to you as a JSON object, but there are no quotes around any of the keys (first_name, last_name, online, or full_name), and there is a function value in the last line. If we want to access the data in the JavaScript object above, we could use dot notation to call user.first_name; and get a string, but if we want to access the full name, we would need to do so by calling user.full_name(); because it is a function.
๐ŸŒ
W3Schools
w3schools.com โ€บ jquery โ€บ ajax_getjson.asp
jQuery getJSON() Method
$("button").click(function(){ ... $("div").append(field + " "); }); }); }); Try it Yourself ยป ยท The getJSON() method is used to get JSON data using an AJAX HTTP GET request....
๐ŸŒ
jQuery
api.jquery.com โ€บ jQuery.getJSON
jQuery.getJSON() | jQuery API Documentation
Description: Load JSON-encoded data from the server using a GET HTTP request. ... A string containing the URL to which the request is sent. ... A plain object or string that is sent to the server with the request. ... A callback function that is executed if the request succeeds.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Response โ€บ json
Response: json() method - Web APIs | MDN
In our fetch JSON example (run fetch JSON live), we create a new request using the Request() constructor, then use it to fetch a .json file. When the fetch is successful, we read and parse the data using json(), then read values out of the resulting objects as you'd expect and insert them into ...