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

13 points
Created by:

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

In JavaScript it is possible to convert json text to plain object variable in following way.

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?
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.