2024-01-05 09:39:59 +00:00
|
|
|
/**
|
|
|
|
|
* Replace bigints with numbers.
|
|
|
|
|
* When parsing parquet files, bigints are used to represent 64-bit integers.
|
|
|
|
|
* However, JSON does not support bigints, so it's helpful to convert to numbers.
|
|
|
|
|
*
|
|
|
|
|
* @param {any} obj object to convert
|
|
|
|
|
* @returns {unknown} converted object
|
|
|
|
|
*/
|
|
|
|
|
export function toJson(obj) {
|
2024-02-14 05:11:34 +00:00
|
|
|
if (obj === undefined) return null
|
|
|
|
|
if (typeof obj === 'bigint') return Number(obj)
|
|
|
|
|
if (Array.isArray(obj)) return obj.map(toJson)
|
|
|
|
|
if (obj instanceof Object) {
|
2024-01-05 09:39:59 +00:00
|
|
|
/** @type {Record<string, unknown>} */
|
|
|
|
|
const newObj = {}
|
|
|
|
|
for (const key of Object.keys(obj)) {
|
|
|
|
|
newObj[key] = toJson(obj[key])
|
|
|
|
|
}
|
|
|
|
|
return newObj
|
|
|
|
|
}
|
2024-02-14 05:11:34 +00:00
|
|
|
return obj
|
2024-01-05 09:39:59 +00:00
|
|
|
}
|