Json.Document
Accessing DataParses JSON text into M values (records, lists, text, numbers, logicals, or null).
Syntax
Json.Document(jsonText as any, optional encoding as nullable number) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
jsonText | any | Yes | The JSON text or binary content to parse. |
encoding | number | No | The text encoding (e.g., TextEncoding.Utf8). Defaults to UTF-8. |
Return Value
any — The 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
AsTableName | Score | |
|---|---|---|
| 1 | Alice | 95 |
| 2 | Bob | 82 |
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])}})Field | Value | |
|---|---|---|
| 1 | status | ok |
| 2 | count | 42 |