Extracting deeply nested JSON values into a flat Excel table is notoriously tedious, often resulting in broken arrays. When pulling API data from standard funding sources, analysts frequently encounter this exact bottleneck. Successfully flattening this dataset grants immediate clarity for strategic financial modeling.
As an educational stipulation, native Excel formulas like FILTERXML require consistent schemas to prevent calculation errors. For example, leveraging Power Query to transform nested records serves as the industry standard to ensure reproducible reporting. Below, we outline the exact formulas and steps to seamlessly automate your JSON flattening process.
With the rise of web APIs, microservices, and modern data pipelines, Excel users frequently find themselves dealing with JSON (JavaScript Object Notation) data. While JSON is excellent for transferring hierarchical, nested data structures, it is notoriously difficult to read or analyze in a standard spreadsheet format. To perform calculations, build PivotTables, or create charts, you must first transpose and flatten these nested JSON values into a structured, flat 2D table.
Historically, converting nested JSON to a table required complex VBA scripts or external conversion tools. Today, with modern Excel (Excel 365 and Excel 2021+), you can achieve this directly using dynamic array formulas (such as LET, TEXTSPLIT, and REDUCE) or through Power Query formula language (M). This guide will walk you through both methods, helping you transform messy nested JSON strings into clean, analysis-ready tables.
Consider a typical JSON object representing an order with nested details, stored in a single Excel cell (for example, cell A2):
{
"OrderID": 10248,
"Customer": "Vins et alcools Chevalier",
"Details": [
{"Product": "Queso Cabrales", "Qty": 12, "Price": 14.00},
{"Product": "Singapura Heere", "Qty": 10, "Price": 9.80}
]
}
A simple transposition won't work here. We need to split the nested Details array so that each product gets its own row, while duplicating the parent information (OrderID and Customer) across those rows. The output should look like this:
| OrderID | Customer | Product | Qty | Price |
|---|---|---|---|---|
| 10248 | Vins et alcools Chevalier | Queso Cabrales | 12 | 14.00 |
| 10248 | Vins et alcools Chevalier | Singapura Heere | 10 | 9.80 |
If you prefer an in-cell worksheet formula that updates in real-time without refreshing data connections, you can leverage Excel's modern text manipulation and dynamic array engines. This formula cleanses the JSON wrappers, parses the elements, and maps them dynamically.
Assuming your raw JSON string is in cell A2, you can use the following formula to split and flatten a semi-structured JSON string. Put this formula in cell B2:
=LET(
raw_text, A2,
clean_text, SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(raw_text, "{", ""), "}", ""), "[", ""), "]", ""),
key_value_pairs, TEXTSPLIT(clean_text, , ","),
split_pairs, TEXTSPLIT(key_value_pairs, ":"),
trimmed_pairs, TRIM(SUBSTITUTE(split_pairs, """", "")),
CHOOSECOLS(trimmed_pairs, 2)
)
LET: Allows us to define variables (like raw_text and clean_text) within the formula to avoid repetitive calculations and make the formula easier to read.SUBSTITUTE: Strips out the curly braces { } and square brackets [ ], which are syntax markers in JSON but get in the way of parsing raw text.TEXTSPLIT(clean_text, , ","): Splits the entire cleaned text string into separate rows using the comma as a row delimiter.TEXTSPLIT(key_value_pairs, ":"): Takes each key-value pair and splits it into two columns (Key in Column 1, Value in Column 2) using the colon delimiter.TRIM & SUBSTITUTE: Cleans up extra whitespace and removes double quotation marks (") surrounding JSON keys and values.CHOOSECOLS: Extracts just the second column (the actual values), effectively transposing the nested keys into a flat vertical array.Note: This basic worksheet formula works best for flat JSON or simple, uniform nested structures. For highly nested objects or variable array lengths, Power Query provides a more robust, zero-code formula interface.
For production environments, complex hierarchies, or multiple API responses, Excel's Power Query engine is the gold standard. It uses a specialized formula language (M) designed specifically for JSON schema parsing and normalization.
Json.Document in the formula bar).[Record] or [List] links.When you click the "Expand" button in the column header, Power Query automatically generates an M formula to flatten your nested values. Below is the code generated in the Advanced Editor that performs the nested expansion:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
// Parse the text column as JSON
ParsedJSON = Table.TransformColumns(Source, {{"JSON_Column", Json.Document, type any}}),
// Expand the outer record keys (OrderID, Customer, Details)
ExpandedRecord = Table.ExpandRecordColumn(ParsedJSON, "JSON_Column", {"OrderID", "Customer", "Details"}, {"OrderID", "Customer", "Details"}),
// Expand the nested JSON list "Details" into new rows
ExpandedDetailsList = Table.ExpandListColumn(ExpandedRecord, "Details"),
// Flatten the nested record fields (Product, Qty, Price)
FlattenedTable = Table.ExpandRecordColumn(ExpandedDetailsList, "Details", {"Product", "Qty", "Price"}, {"Product", "Qty", "Price"})
in
FlattenedTable
In many nested JSON structures, optional fields are omitted entirely rather than being set to null. If using worksheet formulas, you can wrap your extraction logic in an IFERROR or use the new REGEXTEST or REGEXEXTRACT functions (available in newer Insider builds of Excel) to verify if a key exists before trying to split it:
=IFERROR(YourParsingFormula, "N/A")
If you have arrays nested within arrays (e.g., an order containing products, and each product containing a list of sub-components), worksheet formulas can become incredibly complex. In these scenarios, use Power Query's "Drill Down" capability to transform the nested lists into nested tables, and then use Table.ExpandTableColumn to build your master flat table.
| Feature | Dynamic Worksheet Formula (LET/TEXTSPLIT) | Power Query Formula (Json.Document) |
|---|---|---|
| Setup Speed | Instant (Type directly in cell) | Moderate (Requires opening PQ Editor) |
| Execution | Real-time (Automatic recalculation) | On-demand (Requires clicking "Refresh") |
| Complexity Limit | Best for simple or single-depth JSON | Handles infinite levels of nesting |
| Error Handling | Requires manual IFERROR wrappers |
Handled natively by the GUI and M engine |
By mastering these dynamic worksheet functions and Power Query techniques, you can eliminate manual parsing, eliminate the need for third-party file converters, and build clean, automated data pipelines directly inside your Excel workbooks.
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.