Categories

Defaults Deep

Apply deep default values using lodash _.defaultsDeep

Assign default values recursively for undefined properties.

Highlights:

  • Uses lodash _.defaultsDeep
  • Applies defaults deeply to nested objects
  • Only fills in undefined properties

Example:

  • Target: {"a":{"b":1}}
  • Source 1: {"a":{"b":2,"c":3}}
  • Result: {"a":{"b":1,"c":3}}

Enter the target JSON object

First source object

Optional source object

Optional source object

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

Standardizing API request payloads by injecting missing default parameters.
Merging user-defined application settings with factory-default configurations.
Preparing complex data structures for database insertion by ensuring all required fields are present.

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

json

Related 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.

API Documentation

Request Endpoint

POST /en/api/tools/defaults-deep

Request Parameters

Parameter Name Type Required Description
targetObject textarea Yes Enter the target JSON object
source1 textarea Yes First source object
source2 textarea No Optional source object
source3 textarea No Optional source object

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-defaults-deep": {
      "name": "defaults-deep",
      "description": "Apply deep default values using lodash _.defaultsDeep",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=defaults-deep",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]