Axel Rauschmayer on Nostr: #JavaScript: JSON.stringify() only makes \r\n\t visible. Doing the same for other ...
#JavaScript: JSON.stringify() only makes \r\n\t visible. Doing the same for other invisible characters is surprisingly tricky:
> /^\p{Format}$/v.test('\u{200B}')
true
> /\p{Format}/v.test('👨👩👧👦')
true
AFAICT you have to:
• Use JSON.stringify()
• Split the result into graphemes via Intl.Segmenter
• Escape invisible characters
• Join to produce the final result
Published at
2026-11-17 17:36:15 UTCEvent JSON
{
"id": "92f5d897776378745d5f2ab95ab61aa9adf32e450c500b37f910003ccab6bddd",
"pubkey": "7a7a0978cc46ef7fd548fb125e51c04de7d4ca639417a21b56aa95e3711c0b38",
"created_at": 1794936975,
"kind": 1,
"tags": [
[
"proxy",
"https://fosstodon.org/@rauschma/117632989628306569",
"web"
],
[
"t",
"javascript"
],
[
"proxy",
"https://fosstodon.org/users/rauschma/statuses/117632989628306569",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://fosstodon.org/users/rauschma/statuses/117632989628306569",
"pink.momostr"
],
[
"-"
]
],
"content": "#JavaScript: JSON.stringify() only makes \\r\\n\\t visible. Doing the same for other invisible characters is surprisingly tricky:\n\n\u003e /^\\p{Format}$/v.test('\\u{200B}')\ntrue\n\u003e /\\p{Format}/v.test('👨👩👧👦')\ntrue\n\nAFAICT you have to:\n• Use JSON.stringify()\n• Split the result into graphemes via Intl.Segmenter\n• Escape invisible characters\n• Join to produce the final result",
"sig": "2ac14b758c8cbb0b04ef26ca385735ea9e5ae3dd4d7e0aa0f0c366461926cdb0b2dc9c38872082795b640b8ebd1812297bf44805b8f21eb0930140175b6bdc78"
}