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
@aiden-f-dsouzaβ² -13 net votes
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.