re: Pretty JSON Output VIEW POST

TOP OF THREAD FULL DISCUSSION
re: oh ya 😮 ...looking into the docs. it seems like: Throws a SyntaxError exception if the string to parse is not valid JSON. Definitely something to ...
 

I was just curious if there would be a way to recover, for example another parameter you could pass to parse. There isn't though.

const protein = {
  steak: "🥩",
  bacon: "🥓",
  fake: { shrimp: "🍤" },
  array: ["🥩", "🥓", "🍤"]
}
// looks weird but works
JSON.parse(JSON.stringify(protein, null, "\n\t\n\0\r  "))
// SyntaxError
JSON.parse(JSON.stringify(protein, null, "🥓"))

// and my favorite:
// parses as `{sh: "🍤", steak: "🥩", bacon: "🥓"}`
// but breaks nested objects or arrays.
JSON.parse(JSON.stringify({ steak: "🥩", bacon: "🥓" }, null, '"sh":"🍤",'))
code of conduct - report abuse