How to parse a JSON data (type : BigInt) in TypeScript How to parse a JSON data (type : BigInt) in TypeScript json json

How to parse a JSON data (type : BigInt) in TypeScript


I guess you need to do something like this,

export interface Address {id_address: string;}

Then somewhere in your code where you implement this interface you need to do,

const value = BigInt(id_address);  // I am guessing that inside your class you have spread your props and you can access id_address. So inside value you will get your Big integer value.

Reference for BigInt.


If you want to make it reliable and clean then always stringify/parse bigint values as objects:

function replacer( key: string, value: any ): any {    if ( typeof value === 'bigint' ) {        return { '__bigintval__': value.toString() };    }    return value;}function reviver( key: string, value: any ): any {    if ( value != null && typeof value === 'object' && '__bigintval__' in value ) {        return BigInt( value[ '__bigintval__' ] );    }    return value;}JSON.stringify( obj, replacer );JSON.parse( str, reviver );