TypeError: the JSON object must be str, bytes or bytearray, not int: what it means and how to fix it

TL;DR: Validate locally, fix the first real error, validate again (no upload).

Troubleshoot TypeError: the JSON object must be str, bytes or bytearray, not int quickly and validate JSON locally (no upload).

What the error means

TypeError: the JSON object must be str, bytes or bytearray, not int means you called the JSON parser with the wrong input type. json.loads expects a JSON string (or bytes/bytearray), not a Python object like dict/list.

Most common real-world causes

  • You passed None, a dict, or a list into json.loads instead of a JSON string/bytes.
  • You already have a parsed Python object (no json.loads needed).
  • You fetched bytes but did not decode to UTF-8 before parsing (or you decoded incorrectly).
  • A function returned the wrong value (e.g. requests.Response instead of response.text).

Fast debugging steps

  • Print type(value) and repr(value) before calling json.loads.
  • If value is bytes, decode first: value.decode('utf-8', errors='replace').
  • If value is already a dict/list, remove json.loads and use it directly.
  • Add guards: if not isinstance(value, (str, bytes, bytearray)) raise early.

Code example (python)

import json

value = payload  # what you pass into json.loads
print(type(value), repr(value)[:200])

if isinstance(value, (bytes, bytearray)):
    value = value.decode('utf-8', errors='replace')

if not isinstance(value, str):
    raise TypeError("Expected a JSON string/bytes")

obj = json.loads(value)

Fix without uploading data

If the JSON contains sensitive data, validate and fix it locally. No Upload Tools runs 100% in your browser.

Workflow: validate -> fix the first error -> validate again -> export/convert.

FAQ

Does this mean the JSON is invalid? Not necessarily. This error happens before JSON parsing when the input is not a JSON string.

What is the fastest fix? Print type(value) and repr(value), convert bytes to text, and only call json.loads on strings.

Privacy & Security
All processing happens locally in your browser. Files are never uploaded.