parseJson

by FirstBug

HTML

https://jsfiddle.net/#save

JavaScript

var test = {
   "int": 123,
   "intString": "123",
   "Scientific_1_String": "5.56789e+0",
   "Scientific_1": 5.56789e+0,
   "Scientific_2_String": "5.56789e-0",
   "Scientific_2": 5.56789e-0,
   "Scientific_3_String": "3.125e7",
   "Scientific_3": 3.125e7,
   "notNumber": "675.805.714",
   "dg": "675-805-714",
   "hex": "675.805.714",
   "trueString": "true",
   "trueBool": true,
   "falseString": "false",
   "falseBool": false,

 };
 test = JSON.stringify(test);
 //dd = dd.replace(/^string:[+-]?[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?$/g, "$1");
 //dd = dd.replace(/"(-?[\d]+\.?[\d]+)"/g, "$1");
 var parsedJson = JSON.parse(test, function(key, value) {
   if (typeof value === 'string') {
     if (value === 'false') {
       return false;
     } else if (value === 'true') {
       return true;
     } else {
       // try to remove quotes from number types
       value = value.replace(/"(-?[\d]+\.?[\d]+)"/g, "$1");
       return value;
     }
   } else {
     return value;
   }
 });
 console.log(parsedJson);