JavaScript - convert json text to dictionary (map / plain object) variable

13 points
Created by:

In this article, we would like to show you how to convert a JSON text to a dictionary (map / plain object) variable in JavaScript.

In the first versions of JavaScript it was possible to create plain objects and make 5 operations on them: add, update, check, delete and iterate items (called properties). It was called the prototyping process. This way programmers used objects such as Map (Dictionary or associate array) to solve some missing features. ECMAScript 2015 (6th Edition) introduced Map type.

1. JSON.parse example

// ONLINE-RUNNER:browser;

var json = '{"key 1":"value 1", "key 2":"value 2", "key 3":"value 3"}';
var dictionary = JSON.parse(json);

console.log(dictionary['key 1']);
console.log(dictionary['key 2']);
console.log(dictionary['key 3']);

Note: abowe example is nothing more like deserialzaion of json with plain object inside.

See also

  1. JavaScript - deserialize json to object
  2. JavaScript - how to convert json to dictionary from server response?

Alternative titles

  1. JavaScript - how to convert json text to dictionary (map / plain object) variable?
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - JSON

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

â€ïžđŸ’» 🙂