Parse the second argument

JSON.parse(JSON.stringify({
  name"tom".age18.phone"15888787788".IDCard"xxxx"
}), (key, value) = >{
  if(key === "IDCard") {return undefined
  }
  return value;
});   // {name: "tom", age: 18, phone: "15888787788"}
Copy the code

Json. parse converts to depth-first traversal; The value of the last key is null

JSON.parse('{"1": 1, "2": 2, "3": {"4": 4, "5": {"6": 6}}}'.(key, value) = > {
  console.log(key); // log the current property name, the last is "".
  return value;     // return the unchanged property value.
});
/ / 1
/ / 2
/ / 4
/ / 6
/ / 5
/ / 3
/ / ""
Copy the code

JSON. Stringify (obj, replacer). If replacer were a function, each attribute of the serialized value would be converted and processed by that function during serialization; If the parameter is an array, only the property names contained in the array will be serialized into the final JSON string; If this parameter is null or not provided, all enumerable attributes of the object are serialized.

JSON.stringify(foo, ['week'.'month']);
/ / '{" week ": 45," month ": 7}', only keep" week "and" month "attribute values.
Copy the code

If a serialized object has a toJSON method, the toJSON method overrides the default serialization behavior of the object: instead of the object being serialized, the return value from the call to the toJSON method is serialized

var obj = {
  foo: 'foo'.toJSON: function () {
    return 'bar'; }};JSON.stringify(obj);      // '"bar"'
JSON.stringify({x: obj}); // '{"x":"bar"}'
Copy the code