guest271314 (2019-05-03T00:23:11.000Z)
guest271314 at gmail.com (2019-05-03T07:19:40.550Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string and not a JavaScript plain object omit JSON.stringify(), use JSON.parse() with same replacer function , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value)); // {x: undefined, y: undefined, z: undefined} const {z = "a"} = convertJSONNullToUndefined({ x: null, y: 123, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // use negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void 0}"`)); // set value to undefined for (const key in o) yield {[key]: o[key] === `"${void 0}"` ? void o[key] : o[key]} }()); const {z = "a"} = convertJSONNullToUndefined({ x: null, y: 123, z: null }); // "a" assigned to z ```
guest271314 at gmail.com (2019-05-03T07:17:27.225Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string and not a JavaScript plain object omit JSON.stringify(), use JSON.parse() with same replacer function , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value)); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y: 123, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void 0}"`)); for (const key in o) yield {[key]: o[key] === `"${void 0}"` ? void o[key] : o[key]} }()); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y: 123, z: null }); // "a" assigned to z ```
guest271314 at gmail.com (2019-05-03T00:46:57.377Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string and not a JavaScript plain object omit JSON.stringify(), use JSON.parse() with same replacer function // e.g., JSON.parse(`{"x":null,"y":null,"z":null}`, (key, value) => value === null ? `${void 0}` : value) , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value)); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y: 123, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void 0}"`)); for (const key in o) yield {[key]: o[key] === `"${void 0}"` ? void o[key] : o[key]} }()); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y: 123, z: null }); // "a" assigned to z ```
guest271314 at gmail.com (2019-05-03T00:44:56.039Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string and not a JavaScript plain object omit JSON.stringify(), use JSON.parse() with same replacer function // e.g., JSON.parse(`{"x":null,"y":null,"z":null}`, (key, value) => value === null ? `${void 0}` : value) , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value)); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void0}"`)); for (const key in o) yield {[key]: o[key] === `"${void 0}"` ? void o[key] : o[key]} }()); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ```
guest271314 at gmail.com (2019-05-03T00:38:09.168Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string and not a JavaScript plain object omit JSON.stringify(), use JSON.parse() with same replacer function // e.g., JSON.parse(`{"x":null,"y":null,"z":null}`, (key, value) => value === null ? `${void 0}` : value) , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value )); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void 0}"`)); for (const key in o) yield {[key]: o[key] === `"${void 0}"` ? void o[key] : o[key]} }()); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ```
guest271314 at gmail.com (2019-05-03T00:32:15.041Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string and not a JavaScript plain object omit JSON.stringify(), use JSON.parse() with same replacer function // e.g., JSON.parse(`{"x":null,"y":null,"z":null}`, (key, value) => value === null ? `${void 0}` : value) , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value )); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void 0}"`)); for (const key in o) yield {[key]: o[key] == void 0 ? void o[key] : o[key]} }()); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ```
guest271314 at gmail.com (2019-05-03T00:31:21.009Z)
Given input valid JSON JSON.parse() or JSON.stringify() replacer function can be utilized to substitute "undefined" for null. ``` const convertJSONNullToUndefined = json => Object.assign({} // if input is valid JSON string omit JSON.stringify(), use JSON.parse() with same replacer function // e.g., JSON.parse(`{"x":null,"y":null,"z":null}`, (key, value) => value === null ? `${void 0}` : value) , ...Object.entries(JSON.parse(JSON.stringify(json, (key, value) => value === null ? `${void 0}` : value))) .map(([key, value]) => value === `${void 0}` ? {[key]: void value} : value )); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ``` Alternatively RegExp can be used to replace JSON string values ``` const convertJSONNullToUndefined = json => Object.assign({}, ...function*() { // negative lookahead to match ":" followed by null followed by comma or closing curly bracket character // replace null with "undefined" const o = JSON.parse(JSON.stringify(json).replace(/(?![:])null(?=[,}])/g, `"${void 0}"`)); for (const key in o) yield {[key]: o[key] == void 0 ? void o[key] : o[key]} }()); // {x: "undefined", y: "undefined", z: "undefined"} const {z = "a"} = convertJSONNullToUndefined({ x: null, y:null, z: null }); // "a" assigned to z ```