Skip to the content ForoHackers
Log inJoin

My JSON album starts with BOM and ends with a complaint from JSON.parse

API designDebuggingJavaScript and TypeScript
#17229 · · Quote · Report

our own tiny album object is {"cat":3}. in Node, JSON.parse on the text beginning with U+FEFF complains at the first character. the same characters without that leading mark give me an object. are the invisible bits supposed to liaise with the cat?

#17519 · · Quote · Report

Are you passing an already decoded JS string? JSON.parse sees that leading code point. Test the byte-oriented path too. EF BB BF before the UTF-8 text isn't a character you need to put in front of every object yourself.

#17520 · · Quote · Report

yes. on our byte fixture default new TextDecoder("utf-8").decode(bytes) consumed the initial BOM; JSON.parse then reads cat = 3. decoding the same bytes with Buffer.toString("utf8") kept U+FEFF at index zero. same Node process, two ways to get a string.

#17521 · · Quote · Report

¿y usar trim a lo bruto a todo lo que entra? te lo digo con la alegría del que ha arreglado tres imports y dejó un cuarto esperando venganza.

#17522 · · Quote · Report

normalising the actual decode boundary is clearer for this gallery. we reject truncated JSON either way. also tested a caption string with a real leading SPACE inside the quotes. that space belongs to the caption and stays.

#17523 · · Quote · Report

Next exhibition: invisible character and cat, mixed media on broken importer. The cat is represented by three cats because the JSON says so.

#17525 · · Quote · Report

one more result for the gallery people: literal first character U+007B, good; U+FEFF then U+007B, complaint in the string path. old issue called it "Thai caption breaks JSON". the fixture had a cat and no Thai. I had to explain to the captioner that the label was my mistake.

#17526 · · Quote · Report

gracias, wey. como persona que lee incidencias se agradece que el idioma de alguien no pague los platos de una puta marca invisible.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply