@popovmp/json-value-parser
v1.1.0
Published
Parses JSON values to number, boolean, null, or string
Downloads
3
Readme
Parses JSON values to number, boolean, null, or string
Code:
const {parseJsonValue} = require('@popovmp/json-value-parser')
const json = {
"foo" : "bar",
"iNum" : "42",
"iPos" : "+42",
"iNeg" : "-42",
"fNum" : "3.14",
"fPos" : "+.14",
"fNeg" : "-3.1",
"true" : "true",
"false": "false",
"nil" : "null"
};
const obj = {};
for (const key of Object.keys(json)) {
obj[key] = parseJsonValue(json[key]);
}
Output:
const obj = {
foo : "bar",
iNum : 42,
iPos : 42,
iNeg : -42,
fNum : 3.14,
fPos : 0.14,
fNeg : -3.1,
true : true,
false: false,
nil : null,
};