Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > IJsonFileStringifyOptions > ignoreUndefinedValues

IJsonFileStringifyOptions.ignoreUndefinedValues property

By default, JsonFile.stringify() validates that the object does not contain any keys whose value is undefined. To disable this validation, set ignoreUndefinedValues=true which causes such keys to be silently discarded, consistent with the system JSON.stringify().

Signature:

ignoreUndefinedValues?: boolean;

Remarks

The JSON file format can represent null values (JsonNull) but not undefined values. In ECMAScript code however, we generally avoid null and always represent empty states as undefined, because it is the default value of missing/uninitialized variables. (In practice, distinguishing "null" versus "uninitialized" has more drawbacks than benefits.) This poses a problem when serializing ECMAScript objects that contain undefined members. As a safeguard, JsonFile will report an error if any undefined values are encountered during serialization. Set ignoreUndefinedValues=true to disable this safeguard.