Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert map to json js, map to json

const mapToJson = (map) => JSON.stringify(Object.fromEntries(map));
const map = new Map([
  ['user1', 'John'],
  ['user2', 'Kate'],
  ['user3', 'Peter'],
]);
const json = mapToJson(map);
// {"user1":"John","user2":"Kate","user3":"Peter"}
console.log(json);
Comment

convert json to map js, json to map

const jsonToMap = (json) => new Map(Object.entries(JSON.parse(json)));
const json = '{"user1":"John","user2":"Kate","user3":"Peter"}';
const map = jsonToMap(json);
// Kate
console.log(map.get('user2'));
// Map(3) { 'user1' => 'John', 'user2' => 'Kate', 'user3' => 'Peter' }
console.log(map);
Comment

Convertir Map a Json

String jsonString = new Gson().toJson(data, Map.class);
Comment

PREVIOUS NEXT
Code Example
Javascript :: Define the constructor property on the Dog prototype. 
Javascript :: backbone js cdn 
Javascript :: js timezone location 
Javascript :: revert order elements inside array 
Javascript :: get request with axios 
Javascript :: string length in javascript 
Javascript :: getattribute javascript 
Javascript :: Add an item to the beginning of an Array 
Javascript :: try catch async await 
Javascript :: match 
Javascript :: number to float js 
Javascript :: capitalize first letter of each word 
Javascript :: nestjs allow origin 
Javascript :: js concatenate regex 
Javascript :: javascript createelement innerhtml 
Javascript :: javascript string concat vs + 
Javascript :: unix timestamp js 
Javascript :: jquery datepicker 
Javascript :: jquery on multiple events 
Javascript :: dynamic search bar javascript 
Javascript :: Adding a Method to a JavaScript Object 
Javascript :: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String 
Javascript :: nvalid response body while trying to fetch https://registry.npmjs.org/scheduler: Socket timeout 
Javascript :: webpack build watch 
Javascript :: fs fstat 
Javascript :: remove first element of array javascript 
Javascript :: Javascript make alert box 
Javascript :: carousel react 
Javascript :: remove the first item from an array 
Javascript :: how to add options to select in jquery array 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =