json_decode() expects parameter 1 to be string, array given: what it means and how to fix it

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

Troubleshoot json_decode() expects parameter 1 to be string, array given quickly and validate JSON locally (no upload).

What the error means

json_decode() expects parameter 1 to be string, array given means the parser expected valid JSON but encountered a character/token that cannot appear there. In practice, it usually means the input is not JSON (or not strict JSON), or it is incomplete.

Most common real-world causes

  • The input is not strict JSON (single quotes, comments, trailing commas).
  • The response is truncated (missing closing } / ] / ").
  • The response contains a prefix/suffix (logs, banners, debug output).
  • The payload has invalid escapes or control characters in strings.
  • You are parsing the wrong thing (already-parsed object, HTML, CSV, etc).

Fast debugging steps

  • Validate the JSON as-is to get an exact error location.
  • Check the first and last 50 characters for truncation and prefixes.
  • Fix one issue at a time and re-validate after each change.

Code example (php)

$obj = json_decode($text, true);
if (json_last_error() !== JSON_ERROR_NONE) {
  throw new Exception(json_last_error_msg());
}

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 the exact token matter? Yes. The token often hints at the root cause: < is usually HTML, u is often undefined, and / often points to comments.

Should I just regex-fix JSON? Avoid blind regex edits. Validate after each change so you know what you fixed and what broke.

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

Quick fix checklist

  • Reproduce the error on a minimal input.
  • Check type/format and field mapping.
  • Apply the smallest safe fix.
  • Validate on production-like payload.

Related by intent

Useful follow-up pages selected from real search impressions and no-click opportunities.

No-click fix: php json decode arg1 string array givenNo-click fix: php json decode expects string bool givenNo-click fix: php json decode expects string null givenRelated fix: neighbor php go json cannot unmarshal array into field user id type string troubleshooting dRelated fix: neighbor php go json cannot unmarshal array into field user id type string troubleshooting eRelated fix: neighbor php go json cannot unmarshal array into field payload user type string troubleshootRelated fix: neighbor php go json cannot unmarshal array into field user id type string troubleshooting aRelated fix: neighbor php go json cannot unmarshal array into field user id type string troubleshooting eRelated fix: neighbor php go json cannot unmarshal array into field payload user type string troubleshootRelated fix: neighbor php go json cannot unmarshal array into field payload user type string troubleshootRelated fix: neighbor php go json cannot unmarshal array into field payload user type string troubleshootRelated fix: neighbor php csharp stj could not be converted system string token troubleshooting data impoRelated fix: neighbor php csharp stj could not be converted system string items 0 troubleshooting data imRelated fix: neighbor php csharp stj could not be converted system string user id troubleshooting data imRelated fix: neighbor php csharp stj could not be converted system string createdat troubleshooting data Related fix: neighbor php csharp stj could not be converted system string items 0 id troubleshooting dataRelated fix: neighbor php csharp stj could not be converted system string user id troubleshooting edge fuRelated fix: neighbor php go json cannot unmarshal bool into field token type string troubleshooting dataRelated fix: neighbor php go json cannot unmarshal string into field token type int64 troubleshooting datRelated fix: neighbor php go json cannot unmarshal number into field token type string troubleshooting da

Next pages to check

Closest crawled pages without impressions yet. Added to speed first-impression conversion.

neighbor php go json cannot unmarshal array into field payload user type string troublesneighbor php go json cannot unmarshal array into field user id type string troubleshootineighbor csharp go json cannot unmarshal array into field payload user type string checkneighbor csharp go json cannot unmarshal array into field payload user type string checkneighbor csharp go json cannot unmarshal array into field payload user type string workfneighbor csharp go json cannot unmarshal array into field payload user type string workfneighbor csharp go json cannot unmarshal array into field payload user type string workfneighbor csharp go json cannot unmarshal array into field payload user type string workfneighbor csharp go json cannot unmarshal array into field payload user type string workfneighbor csharp go json cannot unmarshal array into field user id type string checklistsneighbor csharp go json cannot unmarshal array into field user id type string runbooks aneighbor csharp go json cannot unmarshal array into field user id type string runbooks wneighbor csharp go json cannot unmarshal array into field user id type string troubleshoneighbor csharp go json cannot unmarshal array into field user id type string troubleshoneighbor csharp go json cannot unmarshal array into field user id type string workflows neighbor csharp go json cannot unmarshal array into field user id type string workflows neighbor csharp go json cannot unmarshal array into field user id type string workflows neighbor csharp go json cannot unmarshal array into field user id type string workflows