Categories

Zip Object

Create an object from keys and values using lodash _.zipObject

Create an object by pairing keys and values by index.

Highlights:

  • Uses lodash _.zipObject
  • Accepts JSON arrays for keys and values
  • Missing values default to undefined

Example:

  • Keys: ["id", "name"]
  • Values: [1, "Ada"]
  • Result: {"id": 1, "name": "Ada"}

Enter a JSON array of keys

Enter a JSON array of values

Key Facts

Category
Data Processing
Input Types
textarea
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The Zip Object tool allows you to quickly transform two separate JSON arrays into a single structured object by pairing keys and values based on their index using the lodash _.zipObject method.

When to Use

  • When you have two parallel arrays of data that need to be combined into a key-value object format.
  • When you need to quickly map a list of identifiers to their corresponding data points for API payloads.
  • When you are cleaning or restructuring raw data arrays into a more readable JSON object format.

How It Works

  • Input your keys as a JSON array in the 'Keys' field.
  • Input your corresponding values as a JSON array in the 'Values' field.
  • The tool automatically pairs the elements by index to generate the resulting object.
  • If the values array is shorter than the keys array, the remaining keys will be assigned an undefined value.

Use Cases

Converting database column headers and row data into JSON objects.
Merging configuration keys with their respective setting values.
Mapping user IDs to user metadata for frontend state management.

Examples

1. Mapping API Response Data

Frontend Developer
Background
I received two separate arrays from an API: one containing field names and another containing the user's profile data.
Problem
I need to convert these into a single object to easily access properties like user.name or user.email.
How to Use
Paste the field names into the Keys field and the profile data into the Values field.
Example Config
Keys: ["username", "email", "role"]
Values: ["jdoe", "[email protected]", "admin"]
Outcome
{"username": "jdoe", "email": "[email protected]", "role": "admin"}

2. Creating Configuration Objects

System Administrator
Background
I have a list of server settings and a list of current values that need to be formatted for a config file.
Problem
Manually typing out the key-value pairs is error-prone and slow.
How to Use
Input the setting names as keys and the current status as values.
Example Config
Keys: ["port", "debug", "ssl"]
Values: [8080, true]
Outcome
{"port": 8080, "debug": true, "ssl": undefined}

Try with Samples

json

Related Hubs

FAQ

What happens if the keys and values arrays have different lengths?

If there are more keys than values, the extra keys will be assigned a value of undefined. If there are more values than keys, the extra values are ignored.

Does this tool support nested objects?

Yes, as long as your input arrays contain valid JSON structures, the tool will pair them into the resulting object.

Is this tool using a standard library?

Yes, this tool utilizes the lodash _.zipObject function to ensure consistent and reliable object creation.

What format should the input be in?

The inputs must be valid JSON arrays, such as ["key1", "key2"] and ["value1", "value2"].

Can I use this for large datasets?

Yes, the tool is designed to handle large arrays efficiently, provided they are formatted as valid JSON.

API Documentation

Request Endpoint

POST /en/api/tools/zip-object

Request Parameters

Parameter Name Type Required Description
keys textarea Yes Enter a JSON array of keys
values textarea Yes Enter a JSON array of values

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-zip-object": {
      "name": "zip-object",
      "description": "Create an object from keys and values using lodash _.zipObject",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=zip-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]