For a Javascript project I have an json string converted into a Javascript object. But the type of all my values is ‘string’ becaus of the JSON parsing.
Is there any solution to identify the types and let a script convert them into the correct javascript type?
for example
//Javascript object for the json decoded string
var jsonObj = { id: "foo", count: "1" };
All the values are of type ‘string’ but I want count to be seen as a number. Is there a parser to set the correct type or does it need to be done manual in JS?
You can use a reviver with
JSON.parse.json2.jsdescribes the reviver thusSo to convert count to a number you might do
so
produces
EDIT
To handle dates as well, you can