Json.Document

Accessing Data

Parses JSON text into M values (records, lists, text, numbers, logicals, or null).

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Json.Document(jsonText as any, optional encoding as nullable number) as any

Parameters

NameTypeRequiredDescription
jsonTextanyYesThe JSON text or binary content to parse.
encodingnumberNoThe text encoding (e.g., TextEncoding.Utf8). Defaults to UTF-8.

Return Value

anyThe M value (record, list, table, text, number, logical, or null) parsed from the JSON content.

Remarks

Json.Document converts a JSON string (or binary) into M values. JSON objects become M records, JSON arrays become M lists, and scalar types map to their M equivalents (text, number, logical, null).

This function is most commonly used with Web.Contents to consume REST APIs:

``powerquery let Response = Web.Contents("https://api.example.com/data"), Parsed = Json.Document(Response) in Parsed ``

After parsing, you typically use Record.Field to access specific keys, or Table.FromRecords to convert a list of records into a table.

Nested JSON objects remain as nested records or lists, which you can expand using Table.ExpandRecordColumn or Table.ExpandListColumn.

Examples

Example 1: Parse a JSON array into a table

let
    JsonText = "[{""Name"":""Alice"",""Score"":95},{""Name"":""Bob"",""Score"":82}]",
    Parsed = Json.Document(JsonText),
    AsTable = Table.FromRecords(Parsed)
in
    AsTable
Result
Name
Score
1Alice95
2Bob82

Example 2: Parse a JSON object

let
    JsonText = "{""status"":""ok"",""count"":42}",
    Parsed = Json.Document(JsonText)
in
    #table({"Field", "Value"}, {{"status", Parsed[status]}, {"count", Text.From(Parsed[count])}})
Result
Field
Value
1statusok
2count42

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks