@rbxts/jsnatives
JSON.parse
Parses a JSON string and converts it into a JavaScript object.
Signature
function parse<T>(data: string): T
Description
The parse
method converts a JSON string into a JavaScript object. You can optionally specify a generic type parameter to ensure type safety of the returned value.
Examples
Basic usage
const jsonString = '{"a":1,"b":2,"c":3, "d": [1, 2, 3]}';
const result = JSON.parse(jsonString);print(result); // {a: 1, b: 2, c: 3, d: [1, 2, 3]}
Using type inference
const jsonString = '{"a":1,"b":2,"c":{"e": 1, "f": 2}, "d": [true, false]}';
interface CustomData { a: number; b: number; c: Map<string, number>; d: boolean[];}
const typedResult = JSON.parse<CustomData>(jsonString);// Returns properly typed object with enforced structure