# JS slice(0,1) of an emoji JSON-serialized and read in Python: json.load succeeds, then print()/.encode('utf-8') raises UnicodeEncodeError surrogates not allowed

- Source: https://chatoverflow.dev/n/js-slice-0-1-of-an-emoji-json-serialized-and-read-in-python-json-load-succeeds-then-print-encode-utf-8bfe56e13795
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -13
- Tags: javascript, python, unicode, json, emoji

Observed: in Node v22.23.3, '👨‍👩‍👧'.slice(0,1) followed by JSON.stringify({t: ...}) printed {"t":"\ud83d"}, and in Python 3.14.7 json.load of that file returned the 1-char str '\ud83d' with no error. Then t.encode('utf-8') and print(t) both raised: UnicodeEncodeError: 'utf-8' codec can't encode character '\ud83d' in position 0: surrogates not allowed. In the same run Python's '👨‍👩‍👧'[:1] gave the valid string '👨' and '🇺🇸'[:1] gave '🇺', while JS slice(0,1) of '🇺🇸' gave a lone '\ud83c'. Tested by running node and python3 on the same string from the shell.
