PowerShell "ConvertFrom-Json: Invalid JSON primitive"

ConvertFrom-Json : Invalid JSON primitive: <something> reads like a JSON syntax error, and sometimes it is one — but just as often the JSON itself is fine and something else entirely is going on.

reference guide PowerShell

// cause 1 — non-JSON text mixed into the pipeline

The single most common trigger: whatever produced the JSON also printed something else first — a progress spinner, a warning line, a login banner from a CLI tool — and it all lands in the same string before reaching ConvertFrom-Json. The cmdlet sees that leading text, not the JSON that follows, and reports it as the invalid primitive. This shows up constantly piping output from CLI tools (Azure CLI, various REST wrappers) that mix status text with their JSON output on the same stream.

If the "invalid primitive" text in the error message is something that isn't part of your actual data at all — a word, a partial sentence, a progress indicator — this is almost certainly what happened. Isolate just the JSON before parsing it, or add whatever flag the source CLI has for JSON-only output (often --output json or similar).
what actually happens, step by step
the code
$result = some-cli-tool get-config
$config = $result | ConvertFrom-Json
what happens
ConvertFrom-Json : Invalid JSON primitive: Loading.
why
some-cli-tool printed "Loading..." to the same output stream before its real JSON. $result is now the string "Loading...\n{ ... }" -- ConvertFrom-Json chokes on "Loading" before it ever reaches the { that starts the real JSON.
the fix
$result = some-cli-tool get-config --output json   # ask for JSON-only output if the CLI supports it
# or, isolate the JSON manually if it doesn't:
$json = ($result -split "`n" | Where-Object { $_ -match '^\s*[\{\[]' }) -join "`n"
$config = $json | ConvertFrom-Json

// cause 2 — genuinely different parsers depending on PowerShell version

This isn't a minor detail — the two major PowerShell lines use entirely different JSON implementations, and they don't agree on what's valid:

Windows PowerShell 5.1 vs. PowerShell 7+
Windows PowerShell 5.1ConvertFrom-Json is built on JavaScriptSerializer — stricter about some things. Historically rejects JSON containing comments outright, and this is the version that ships built into Windows, so it's the one most people hit without choosing to
PowerShell 7+ConvertFrom-Json is built on Newtonsoft Json.NET — more lenient. Accepts comments in the JSON, and generally tolerates input that 5.1 would reject outright
If the exact same JSON string works in one PowerShell session but not another, checking $PSVersionTable.PSVersion in both is worth doing before anything else — it's frequently the actual explanation, not a subtle bug in the data.
check which one you're actually running
PS> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  5486        <-- Windows PowerShell 5.1: JavaScriptSerializer, stricter
# vs.
7      4      6                  <-- PowerShell 7+: Newtonsoft Json.NET, more lenient

// try it yourself

Paste the raw string being handed to ConvertFrom-Json into the JSON Formatter — if it's genuinely malformed JSON rather than non-JSON text mixed in, this will point at the exact spot and can usually auto-fix it.