Categories

Assign Object

Assign source properties to a target object using lodash _.assign

Assign own enumerable properties from sources to the target object.

Highlights:

  • Uses lodash _.assign
  • Later sources override earlier ones
  • Returns the merged object

Example:

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

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

The Assign Object tool allows you to efficiently merge source properties into a target JSON object using the lodash _.assign method, ensuring that later sources override any conflicting properties from earlier ones.

When to Use

  • When you need to update a base configuration object with new values from multiple sources.
  • When you want to consolidate several JSON objects into a single, unified data structure.
  • When you need to apply property overrides programmatically without manually editing complex JSON files.

How It Works

  • Input your base JSON structure into the Target Object field.
  • Add your source objects into the provided Source fields.
  • The tool processes the inputs using lodash _.assign, where subsequent sources take precedence over previous ones.
  • Retrieve the final merged JSON object as the output.

Use Cases

Merging default application settings with user-specific overrides.
Combining partial data fragments from different API responses into a single record.
Updating state objects in a predictable, sequential manner.

Examples

1. Updating User Profile Settings

Frontend Developer
Background
A user profile object needs to be updated with new preferences received from a settings form.
Problem
Manually merging the base profile with new settings is error-prone.
How to Use
Paste the current profile into Target Object and the new settings into Source 1.
Example Config
Target: {"theme": "light", "notifications": true}, Source 1: {"theme": "dark"}
Outcome
The resulting object is {"theme": "dark", "notifications": true}.

2. Consolidating Configuration Layers

DevOps Engineer
Background
An application requires a base configuration that is extended by environment-specific overrides.
Problem
Need to ensure production overrides correctly replace development defaults.
How to Use
Place base config in Target, environment defaults in Source 1, and specific overrides in Source 2.
Example Config
Target: {"port": 8080, "debug": true}, Source 1: {"port": 3000}, Source 2: {"debug": false}
Outcome
The final configuration results in {"port": 3000, "debug": false}.

Try with Samples

json

Related Hubs

FAQ

What happens if two sources have the same key?

The value from the source that appears later in the input sequence will overwrite the value from the earlier source.

Does this tool perform a deep merge?

No, this tool uses lodash _.assign, which performs a shallow assignment of own enumerable properties.

What format should the input objects be in?

Inputs must be valid JSON objects enclosed in curly braces.

Are non-enumerable properties included?

No, only the source object's own enumerable properties are assigned to the target.

Can I use this to merge more than two objects?

Yes, you can provide a target object and up to three additional source objects to be merged in sequence.

API Documentation

Request Endpoint

POST /en/api/tools/assign-object

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-assign-object": {
      "name": "assign-object",
      "description": "Assign source properties to a target object using lodash _.assign",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=assign-object",
      "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]