bozzltron / node-json-transform

A node module for restructuring and performing operations on JSON on the fly.
172 stars 53 forks source link

Defaults #29

Open fyarepo opened 6 years ago

fyarepo commented 6 years ago

Hi, I try defaults options, but it does not add to output, What can I do? Regards gab

    defaults: {
        "missingData": true
    },
churrinfunflais commented 4 years ago

Hi, I try defaults options, but it does not add to output, What can I do? Regards gab

    defaults: {
        "missingData": true
    },

@fyarepo same here, did you make it work?

churrinfunflais commented 4 years ago

Just figured out,

var map = {
...
     item: {
        .....
        missingData: 'undefined'
    },
     defaults: {
          missingData: true
     },
...
}
bozzltron commented 4 years ago

Defaults fill in data where it is missing per item.

Here is the test: https://github.com/bozzltron/node-json-transform/blob/806d00e25535c659f0c01f10c5759ba227131633/test/nodeDataTransformSpec.js#L332

ihorTymofieiev commented 3 years ago

You need to use undefined for all fields with no string default value.

item: {
        .....
        fieldWithBooleanDefaultValue: 'undefined'
    },
         defaults: {
          fieldWithBooleanDefaultValue: false
     },

cc. @fyarepo @churrinfunflais

ns-pbhatti commented 2 years ago

Yes @ihorTymofieiev above works for me!. This issue can be closed