Great to hear it worked! π Here's a quick breakdown of what that expression does:
---
Expression: $.mapKeys((value, key) => key.toLowerCase())
What it does
This expression transforms all keys of the current input document ($) to lowercase.
How it works
| Part | Description |
|---|---|
| $ | Refers to the entire current input document (a JSON object) |
| .mapKeys(fn) | Iterates over every key-value pair in the object and replaces each key with the return value of the function |
| (value, key) => key.toLowerCase() | An arrow function that takes each value and key, and returns the key converted to lowercase |
Example
Input:
json
{
"FirstName": "Alice",
"LAST_NAME": "Smith",
"Age": 30
}
Output:
json
{
"firstname": "Alice",
"last_name": "Smith",
"age": 30
}
π‘ Note: Only the keys are transformed β the values remain unchanged.
---
This is a handy pattern for normalizing field names, especially when dealing with inconsistent casing from upstream sources. Let me know if you'd like to extend this further, such as also transforming values or filtering specific keys!