0

I am trying to convert an object containing map to json using JSON.stringify(). But after the conversion map data gets cleared. How do i solve this issue?

frieghtChargesJSon:string; //declared variable frieghtChargesJSon=JSON.stringify(frieghtChargeInfo)

I want to convert object itself to JSon ,not just the map

0

1 Answer 1

0

You can use

string = JSON.stringify(Array.from(map.entries()));
4
  • I want entire Object to be converted into JSON not just the map
    – shyni
    Commented Jan 28, 2019 at 10:52
  • @shyni const mapObj = m => { return Array.from(m).reduce((obj, [key, value]) => { obj[key] = value; return obj; }, {}); }; JSON.stringify(mapObj(map)); Commented Jan 28, 2019 at 10:54
  • Actually this doesn't work for me .It doesn't convert entire Object to JSON
    – shyni
    Commented Jan 28, 2019 at 11:24
  • Thanks for your help
    – shyni
    Commented Jan 28, 2019 at 11:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.