Skip to content

Commit 226e639

Browse files
authored
Merge pull request #98 from burgdoerfer-solutions/fix/null-fields
Handle fields with `null` value
2 parents 9641b05 + aeafa7d commit 226e639

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function objToJson (obj) {
1515
return Object.keys(obj).reduce(function (memo, key) {
1616
if (typeof obj[key] === 'function') {
1717
memo[key] = obj[key].toString()
18-
} else if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
18+
} else if (typeof obj[key] === 'object' && !Array.isArray(obj[key]) && obj[key] !== null) {
1919
memo[key] = objToJson(obj[key])
2020
} else {
2121
memo[key] = obj[key]

test/expected/null-example.js.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"_id": "null-example",
3+
"null-field": null
4+
}

test/fixtures/null-example.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
_id: 'null-example',
3+
'null-field': null
4+
}

0 commit comments

Comments
 (0)