guest271314 (2019-05-11T16:19:51.000Z)
guest271314 at gmail.com (2019-05-11T17:57:31.887Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ``` Alternatively a single use function expecting a single input parameter that is a valid JSON string consisting of a ```{"key":"value"}``` ``` const convertJSONNullToUndefined = (json, o = JSON.parse(json), [k] = Object.keys(o), res = o[k] !== null ? o : {[k]: void 0}) => res; const { z = 'a' } = convertJSONNullToUndefined(`{"z":null}`); ``` Since ```.find()``` returns ```undefined``` if the value is not matched ``` const [z = 'a'] = [Object.values(JSON.parse(`{"z":null}`)).find(value => value !== null)]; ``` or ``` const [z = 'a'] = Object.values(JSON.parse(`{"z":null}`)).filter(value => value !== null); ```
guest271314 at gmail.com (2019-05-11T17:49:22.591Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ``` Alternatively a single use function expecting a single input parameter that is a valid JSON string consisting of a ```{"key":"value"}``` ``` const convertJSONNullToUndefined = (json, o = JSON.parse(json), [k] = Object.keys(o), res = o[k] !== null ? o : {[k]: void 0}) => res; const { z = 'a' } = convertJSONNullToUndefined(`{"z":null}`); ``` Since ```.find()``` returns ```undefined``` if the value is not matched ``` const [z = 'a'] = [Object.values(JSON.parse(`{"z":null}`)).find(value => value !== null)]; ```
guest271314 at gmail.com (2019-05-11T17:48:58.307Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ``` Alternatively a single use function expecting a single input parameter that is a valid JSON string consisting of a ```{"key":"value"}``` ``` const convertJSONNullToUndefined = (json, o = JSON.parse(json), [k] = Object.keys(o), res = o[k] !== null ? o : {[k]: void 0}) => res; const { z = 'a' } = convertJSONNullToUndefined(`{"z":null}`); ``` Since ```.find()``` returns ```undefined``` ``` const [z = 'a'] = [Object.values(JSON.parse(`{"z":null}`)).find(value => value !== null)]; ```
guest271314 at gmail.com (2019-05-11T17:09:46.068Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ``` Alternatively a single use function expecting a single input parameter that is a valid JSON string consisting of a ```{"key":"value"}``` ``` const convertJSONNullToUndefined = (json, o = JSON.parse(json), [k] = Object.keys(o), res = o[k] !== null ? o : {[k]: void 0}) => res; const { z = 'a' } = convertJSONNullToUndefined(`{"z":null}`); ```
guest271314 at gmail.com (2019-05-11T17:08:18.851Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ``` Alternatively a single use function expecting a single input parameter that is a valid JSON string consisting of a ```{"key":"value"}``` ``` const convertJSONNullToUndefined = (json, o = JSON.parse(json), [k] = Object.keys(o), res = o[k] !== null ? o : {[k]: void 0}) => res; const { z = 'a' } = fn(`{"z":null}`); ```
guest271314 at gmail.com (2019-05-11T17:07:43.398Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ``` Alternatively a single use function expecting a single input parameter that is a valid JSON string consisting of a ```{"key":"value"}``` ``` const convertJSONNullToUndefined = (json, o = JSON.parse(o), [k] = Object.keys(o), res = o[k] !== null ? o : {[k]: void 0}) => res; const { z = 'a' } = fn(`{"z":null}`); ```
guest271314 at gmail.com (2019-05-11T16:23:18.891Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o; } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ```
guest271314 at gmail.com (2019-05-11T16:22:58.097Z)
Slightly less code (still un-golfed as that does not appear to be the stated requirement described at OP) using the same/similar pattern. ``` let input_json_string = `{"z":null}`; const convertJSONNullToUndefined = json => { const o = JSON.parse(json); for (const key in o) if (o[key] === null) o[key] = void 0; return o } convertJSONNullToUndefined(input_json_string); // do destructuring stuff ```