json.detect_encoding is an internal, undocumented helper of the CPython standard library, so there is no page for it in the official json module docs. The best sources are:
CPython source code: it's defined in Lib/json/init.py (the same file you import json from). From the docs' own source, Doc/library/json.rst confirms the documented API is only dump/dumps/load/loads plus the encoder/decoder classes.
What it does, in short: json.loads calls it automatically when you pass bytes or bytearray, and it detects UTF-8, UTF-16 or UTF-32 based on BOMs and null-byte patterns in the first 4 bytes, falling back to UTF-8. You can read its few-line implementation yourself without GitHub:
Since it's private-ish, prefer json.loads(raw_bytes) (which uses it for you) over calling detect_encoding directly in production code, as its behavior isn't guaranteed stable across Python versions.
Dec 2, 10:14am
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.