Skip to main content

Function: normalize()

normalize(rows): Row[]

Defined in: src/parsers/_normalize.ts:132

json_normalize equivalent: flatten an array of (possibly nested) row objects into rectangular rows with deep _-joined, snake_cased keys. Array-valued cells are stringified; an id column of integers becomes decimal strings. Non-array / empty input returns [].

Parameters​

rows​

any[]

The records to flatten. A non-array (an object, null, undefined) or an empty array yields []. A non-object element is kept under a single value column (an array element as its JSON.stringify text).

Returns​

Row[]

New row objects with deep _-joined, snakeCased keys and no nested structures: nested objects flatten, array cells are JSON.stringify'd. Rows are NOT padded to a common column set — a key absent from a record is absent from its row.

Remarks​

Mirrors sdv-py mlb/mlb_parsers.py::_flatten_rows (pandas.json_normalize). The id rule (idColumnsToStrings, src/core/int64.ts) runs last and in place over the new rows: an id column (id, *_id, *_ids, *_pk) whose non-null cells are all exact integers becomes decimal strings (13 -> "13", -0 -> "0"); a JSON string id is kept exactly; a column holding a fraction, boolean or a number past 2^53 is left as read. Two source keys that snake_case to the same name overwrite each other (last wins) — unlike rowsToFrame.

Example​

const rows = normalize(payload.dates[0].games);
rows[0].teams_home_team_id; // "147"