flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.01k stars 87 forks source link

ERROR Error: Not a valid SuperJSON payload. #56

Closed xinqm0217 closed 4 years ago

xinqm0217 commented 4 years ago

const obj = { e: 123, f: 'str2', }; const str = JSON.stringify(obj); const result = superjson.parse(str);

ERROR Error: Not a valid SuperJSON payload.

Skn0tt commented 4 years ago

You'll need to stringify using SuperJSON:

const obj = {
  e: 123,
  f: 'str2',
};
const str = SuperJSON.stringify(obj); // 👈 you used JSON instead of SuperJSON
const result = SuperJSON.parse(str);