LoginSignup
0
0

More than 1 year has passed since last update.

javascriptでobjectをjson(文字列)にする

Posted at

単純に JSON.stringify で良いじゃんっていう記事が多いけどできないことがあったので別解。

const obj = {a: 2, b: 3, c: 5, d:{"x":200,"v":300,"z":800}};
const json = JSON.stringify(Object.fromEntries(Object.entries(obj)));
//{"a":2,"b":3,"c":5,"d":{"x":200,"v":300,"z":800}}
JSON.parse(json).d.v;
//300

toSource とかも出てきたので非推奨で廃止済みなので論外。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0