Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Json.Document: How to Parse JSON in Power Query

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Json.Document is the Power Query M function that converts a JSON text value into structured data you can work with — records, lists, and tables. You call it when your source hands you raw JSON text (a web API response, a local file, a cell value, or a column pulled from a database) but you need fields, columns and names you can actually expand and transform. Nothing extra is required beyond Power Query itself, which is built into Excel (Data > Get Data) and Power BI (Transform data); an internet connection is only needed if the JSON comes from a web endpoint.

What You'll Need

  • Excel 2016 or later (or a Microsoft 365 subscription) with Power Query, or Power BI Desktop. The function is also available in the Power Query Online editor inside Fabric and Power Platform dataflows.
  • The JSON itself, or a way to reach it: a URL, a file path, a table column, or a text value. A URL-based call may need an API key or token, depending on the service.
  • Basic familiarity with Power Query's Advanced Editor, since Json.Document is normally typed rather than clicked. You open it from Home > Advanced Editor; exact button positions vary slightly by version and product.

Step-by-Step

  1. Get the raw JSON into a query. For a URL, use Data > Get Data > From Other Sources > From Web, enter the address, and stop at the navigator — choose the root/raw item if one is offered, or just load whatever the dialog shows. For a file, use Get Data > From File > From JSON. The goal is a single text value, not a half-parsed table.
  2. Alternatively, pull JSON from a table column. If a database or CSV has a column holding JSON text, load that table first, click the column, then Add Column > Custom Column. This is the cleanest route when you have one JSON document per row.
  3. Write the call. In a custom column, use a formula such as Json.Document([JsonColumn]). In the Advanced Editor, wrap your text source: if the previous step is named Source, the new step is Json.Document(Source). Notice the two arguments the function accepts: the required text (or binary value) and an optional encoding record.
  4. Read the result type. Check the icon or the output after the step. A JSON object becomes a record (shown with curly-bracket fields), a JSON array becomes a list, and an array of objects — the usual API shape — becomes a list of records that Power Query offers to convert to a table.
  5. Convert lists of records to a table. Click the List Tools > To Table button (or add Table.FromList(..., Splitter.SplitByNothing(), null, null, ExtraValues.Error) yourself). You get one column, usually named Column1, holding one record per row.
  6. Expand the records into columns. Click the expand icon at the column header and choose the fields you need. Untick "Use original column name as prefix" if you want clean headers. Repeat for nested records: each expansion reveals the next level.
  7. Handle nested lists separately. A JSON array inside a field appears as a List value, not a record. You can expand it to new rows (this duplicates the parent row per item) or, if you want a single flattened value, use Extract Values or Text.Combine on a converted list. Choose deliberately — expanding to rows multiplies row counts and will break a join or a count if you are not expecting it.
  8. Set data types explicitly. Expanded fields often arrive as Any or Text. Select the column and set the type (Whole Number, Decimal Number, Date) from the Transform tab or the small icon at the top-left of the header. JSON numbers are untyped, so dates in particular will be text until you convert them.
  9. Test with a single record first. Before expanding a large feed, filter to one item and confirm the shape of the hierarchy. It is far faster to inspect two levels on one record than to expand a 50,000-row feed and hunt for the missing field afterwards.
  10. Harden against missing fields. If some records lack a key, expansion simply yields nulls — that is fine. But if the top level is sometimes an object and sometimes an array, the query breaks; add a conditional such as if Value.Is(x, type list) then ... else ... to cope with both.
  11. Load and refresh. Click Close & Load (Excel) or apply the changes (Power BI). On refresh, the same Json.Document step re-runs against the source, so any schema change upstream will surface at refresh time, not at design time.

Common Mistakes

Passing already-parsed data. If the previous step is a table or record, Json.Document fails with a type mismatch. It wants text or binary. In From Web queries, the navigator has often parsed the JSON for you; going back to the raw content step is the fix.

Forgetting the encoding record. Non-English characters come back garbled if the source is not UTF-8. Supply the second argument, e.g. Json.Document(Source, [Encoding.Text = 65001]), only after confirming the actual encoding; guessing wrong makes it worse.

Expanding a list instead of a record, or vice versa. Lists expand to rows and records expand to columns. Mixing them up produces a one-column table of nulls, which people often misread as a broken source.

Losing source column names. Expanding with the prefix option on gives headers like "Column1.field". Clean them once and reuse the query rather than renaming every field by hand.

Trusting declared types. JSON has no dates, and numbers can arrive as strings ("12" rather than 12). Set types explicitly after expansion; relying on column detection leaves mixed-type columns that fail later.

Tips

Keep one query that only parses the JSON, and separate queries that shape it. That way a schema change only affects the parser. Name every step meaningfully — the step list is your only documentation.

Use the Advanced Editor's one-line test trick: temporarily replace the final step with a Json.Document wrapped around a literal text string to experiment with a small sample without hitting the network.

If the feed is an OpenAPI service, Get Data > From Other Sources > From Web may offer a structured connector that avoids manual expansion entirely. For very large documents, filter before expanding — expansion multiplies rows and slows refreshes.

Troubleshooting

"Expression.Error: We cannot convert a value of type Table to type Text." You fed a table. Reference the raw-content step, not the navigated table.

"We found extra characters at the end of JSON input." The text has trailing content or concatenated documents. Trim, split, or ask the API for a single document.

All fields show null after expansion. The field names differ in case or spelling between records, or you expanded the wrong level of the hierarchy. Re-check one record's actual keys.

Refresh fails but it worked yesterday. The API changed shape, expired its token, or returned an error page. Use the source step to view the raw content and confirm what came back before editing the query.

Credentials error on a web call. Set up authentication at Data > Get Data > Data Source Settings, then clear permissions and retry. Deleted permissions can be re-entered; they are not lost data.

Frequently Asked Questions

What is the difference between Json.Document and Web.Contents?

Web.Contents fetches text from a URL. Json.Document converts that text into records, lists and tables. Typically you use both, one after the other.

Can Json.Document read a JSON file directly?

Yes. From File > From JSON does this for you. If you fetch the file's binary content yourself, Json.Document accepts binary as well as text.

Does it work in Power BI Desktop and the service?

Yes. The M engine is the same, so a query that parses correctly on the desktop refreshes the same way in the service, subject to gateway and credential setup.

How do I get a single value out of a JSON field?

After expansion, click the value and use Drill Down, or reference the field with square brackets, e.g. record[fieldName]. Drill Down turns the query into a scalar result.

Why does my column disappear after expanding?

Power Query keeps only fields you ticked. Re-open the expand menu and add the field, or use "Load more" if the list was truncated.

Can I parse JSON from a cell in Excel?

Yes, if the cell is loaded into Power Query as part of a table. Add a custom column with Json.Document([ColumnName]) and expand the result.