JSON Extractor:
The JSONExtractor node is designed to facilitate the extraction of specific values from a JSON string using a designated key. This node is particularly useful for AI artists and developers who need to parse JSON data and retrieve specific information without delving into complex coding. By allowing you to specify a key, including nested keys, the JSONExtractor efficiently navigates through the JSON structure to find and return the desired value. This capability is essential for workflows that involve processing JSON data, enabling you to seamlessly integrate and utilize JSON-derived information in your projects. The node ensures that the extracted values are preserved in their native types, making them readily usable for downstream processes.
JSON Extractor Input Parameters:
json_string
The json_string parameter is a required input that expects a JSON-formatted string. This string serves as the source from which the node will extract the desired value. It is crucial that the input is a valid JSON string, as any deviation from the JSON format will result in an error. This parameter does not have a default value, and you must provide a valid JSON string for the node to function correctly.
key
The key parameter is a required input that specifies the key whose value you wish to extract from the JSON string. This key can be a simple key or a nested key, using dot notation (e.g., user.profile.name) to access values within nested JSON objects. The default value for this parameter is an empty string, and you should provide a valid key to ensure successful extraction of the desired value.
JSON Extractor Output Parameters:
value
The value output parameter represents the extracted value from the JSON string based on the specified key. This output can be of any JSON-compatible type, such as a string, number, boolean, null, object, or array. The node ensures that the extracted value is preserved in its native type, allowing for seamless integration with other nodes or processes that may require specific data types.
JSON Extractor Usage Tips:
- Ensure that the
json_stringinput is a valid JSON format to avoid errors during extraction. - Use dot notation in the
keyparameter to access nested values within the JSON structure, which can be particularly useful for complex JSON data.
JSON Extractor Common Errors and Solutions:
Invalid JSON: <error_message>
- Explanation: This error occurs when the provided
json_stringis not in a valid JSON format, preventing the node from parsing it. - Solution: Verify that the
json_stringis correctly formatted as JSON. Use online JSON validators to check and correct any formatting issues.
Key '<key>' not found
- Explanation: This error indicates that the specified key does not exist within the JSON structure, making it impossible to extract a value.
- Solution: Double-check the key for typos or incorrect paths. Ensure that the key matches the structure of the JSON data, especially when using nested keys.
Cannot access key '<key>' on non-dict value
- Explanation: This error arises when attempting to access a key on a value that is not a dictionary, which is necessary for key-based access.
- Solution: Review the JSON structure to ensure that the path specified by the key leads to a dictionary object. Adjust the key path as needed to align with the JSON hierarchy.
