Languages
[Edit]
EN

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

13 points
Created by:
Kate_C
22250

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?

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.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join