Categories

Has In Path

Check if a path exists using lodash _.hasIn

Check if a property path exists on an object, including inherited properties.

Highlights:

  • Uses lodash _.hasIn
  • Checks own and inherited properties
  • Returns true or false

Example:

  • Input: {"user":{"name":"Ada"}}
  • Path: user.name
  • Result: true

Enter a JSON object or array

Property path to check

Key Facts

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

Overview

The Has In Path tool allows you to verify the existence of a specific property path within a JSON object or array, including properties inherited through the prototype chain.

When to Use

  • When you need to confirm if a nested property exists in a complex data structure.
  • When you must account for inherited properties that standard existence checks might miss.
  • When debugging data objects to ensure required keys are present before processing.

How It Works

  • Paste your JSON object or array into the input field.
  • Specify the dot-notation path you wish to verify (e.g., user.profile.id).
  • The tool utilizes lodash's _.hasIn method to perform a deep check.
  • Receive a boolean true or false result indicating if the path exists.

Use Cases

Validating configuration objects that rely on prototype inheritance.
Checking for the presence of nested API response fields before mapping data.
Debugging data structures where properties might be defined on the prototype.

Examples

1. Verify Nested User Property

Background
A developer needs to ensure a user object contains a nested 'settings' object before applying default configurations.
Problem
The developer is unsure if the 'settings' key exists in the user object.
How to Use
Input the user JSON object and set the path to 'user.settings'.
Example Config
Input: {"user": {"settings": {"theme": "dark"}}}, Path: user.settings
Outcome
The tool returns 'true', confirming the path exists.

2. Check Inherited Property

Background
An application uses objects created via constructors where common methods or properties are stored on the prototype.
Problem
Standard existence checks fail to detect properties defined on the prototype chain.
How to Use
Input the object and the path to the inherited property.
Example Config
Input: {"type": "vehicle"}, Path: toString
Outcome
The tool returns 'true' because 'toString' is an inherited property of the object.

Try with Samples

json

Related Hubs

FAQ

What is the difference between hasIn and has?

The hasIn method checks both own and inherited properties, whereas standard has checks only for own properties.

Does this tool support array indices in the path?

Yes, you can use dot notation to access array indices, such as users.0.name.

What happens if the input JSON is invalid?

The tool will return an error indicating that the provided input is not a valid JSON format.

Can I check for properties on a null or undefined object?

If the base object is null or undefined, the tool will return false as the path cannot be resolved.

Is the check case-sensitive?

Yes, property names in the path must match the casing of the keys in your JSON exactly.

API Documentation

Request Endpoint

POST /en/api/tools/has-in-path

Request Parameters

Parameter Name Type Required Description
inputData textarea Yes Enter a JSON object or array
path text Yes Property path to check

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-has-in-path": {
      "name": "has-in-path",
      "description": "Check if a path exists using lodash _.hasIn",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=has-in-path",
      "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]