Validate a decoded JSON value at the boundary
Decoding JSON proves that the text is valid JSON, not that its shape is suitable for your program. A boundary validator should reject the wrong container, missing fields and misleading scalar types. In Python, bool is a subclass of int, so isinstance alone may accidentally accept True as a numeric identifier. State those rules explicitly.
import json
value = json.loads('{"count": true}')
print(type(value["count"]) is int)Think before coding
The boundary converts loosely structured input into one trustworthy value. Exact integer checking avoids the bool subclass trap. All rejected inputs share a clear ValueError contract. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write parse_count(text). Decode a JSON object and return its count only if that value has exactly type int and is nonnegative. Raise ValueError for invalid JSON, a wrong shape, a missing key, bool, or any other count type. Ignore other keys.
The explanation opens here once every check passes.