Key Facts
- Category
- Data Processing
- Input Types
- textarea
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
Defaults Deep allows you to recursively merge default values into your JSON objects using the lodash _.defaultsDeep method, ensuring your data structures are complete without overwriting existing defined properties.
When to Use
- •When you need to populate missing configuration settings in a nested JSON object.
- •When merging user-provided input with a set of required system defaults.
- •When you want to ensure specific keys exist in a data structure while preserving current values.
How It Works
- •Input your primary target object containing your current data.
- •Provide one or more source objects containing the default values you wish to apply.
- •The tool recursively traverses the objects, assigning values from the sources only where the target property is undefined.
- •Receive the merged JSON object with all missing nested properties filled in.
Use Cases
Examples
1. Merging Application Settings
Frontend Developer- Background
- An application has a user-defined theme object that might be missing certain nested color or spacing properties.
- Problem
- The UI breaks when expected nested properties are missing from the user's saved configuration.
- How to Use
- Paste the user's partial configuration into the Target Object field and the full theme schema into Source 1.
- Example Config
-
Target: {"theme": {"primary": "blue"}} | Source 1: {"theme": {"primary": "red", "spacing": "10px"}} - Outcome
- The result is {"theme": {"primary": "blue", "spacing": "10px"}}, preserving the user's primary color while adding the missing spacing.
2. API Payload Normalization
Backend Engineer- Background
- Incoming requests from a client are missing several optional fields that the backend service requires to function correctly.
- Problem
- The service logic fails because it expects a complete object structure.
- How to Use
- Use the incoming request as the Target Object and a template of default values as Source 1.
- Example Config
-
Target: {"settings": {"notifications": true}} | Source 1: {"settings": {"notifications": false, "theme": "dark"}} - Outcome
- The result is {"settings": {"notifications": true, "theme": "dark"}}, ensuring the 'theme' key is present without changing the user's 'notifications' preference.
Try with Samples
jsonRelated Hubs
FAQ
Does this tool overwrite existing values?
No, it only assigns values to properties that are currently undefined in the target object.
Can it handle deeply nested objects?
Yes, the tool uses lodash _.defaultsDeep, which performs a recursive merge across all levels of the object hierarchy.
What happens if a property is null?
Since null is a defined value, the tool will not overwrite it with the default value.
How many source objects can I provide?
You can provide up to three source objects to merge into your target object.
Is the output valid JSON?
Yes, the tool returns a clean, valid JSON string representing the merged object.