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[k
The bytes used for code can be reduced. Used redundancy in the original
code to handle both cases at the actual examples at OP.
```JSON.stringify()``` and ```replace()``` could be used. The original
proposal mentions ```JSON```, though includes the case of
```
const { y =? 'a' } = { y: undefined }
> Given input valid JSON JSON.parse() or JSON.stringify() replacer function can
> be utilized to substitute "undefined" for null.
guest271314, that’s a lot of code! It feels like if anything, your example
backs up the proposal.
> `const { z =? 'a' } = { z: null };`
I’m not sure I like the prop
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
/
Similarly to
```js
const { x = 'a' } = {}; // z === 'a'
const { y = 'a' } = { y: undefined }; // z === 'a'
const { z = 'a' } = { z: null }; // z === null
```
I'd like to propose
```js
const { x =? 'a' } = {}; // z === 'a'
const { y =? 'a' } = { y: undefined }; // z === 'a'
const { z =? 'a' } = {
5 matches
Mail list logo