Skip to main content

Color Decode

Parse Data Analysis

Synopsis

Processes and converts between different color format representations.

Schema

- color_decode:
field: <ident>
output_format: <string>
target_field: <ident>
input_format: <string>
uppercase: <boolean>
short_hex: <boolean>
percent_rgb: <boolean>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Source field containing color data to convert
output_formatNhexTarget color format: hex, rgb, rgba, hsl, hsla, hsv, hsva, name, rgb_array, hsl_array, hsv_array. An omitted or unrecognised value falls back to hex rather than failing
target_fieldNSame as fieldTarget field to store the converted color
input_formatNautoInput color format: auto, hex, rgb, hsl, hsv, name
uppercaseNfalseOutput hex values in uppercase
short_hexNfalseOutput 3-character hex when possible (e.g., "#f00" vs "#ff0000")
percent_rgbNfalseOutput RGB values as percentages instead of 0-255
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if conversion fails
ignore_missingNfalseSkip processing if referenced field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration

Details

Converts color values between various common color formats including hex, RGB, HSL, HSV, and named colors. The processor can automatically detect the input format or work with explicitly specified formats.

The processor supports both simple color conversion and options such as percentage-based RGB values and shortened hex notation.

Alpha is read from the input, never configured. A color written with an alpha component — rgba(), hsla(), or 8-digit hex — carries it through; anything else is fully opaque. An a-suffixed output_format (rgba, hsla, hsva) always emits the component, so an opaque input renders as 1.00.

note

When input_format is set to "auto", the processor attempts to automatically detect the color format based on the input string pattern. This works with most common color representations.

The output format determines the structure of the converted color value. Array formats (like rgb_array) return numerical arrays, while string formats return formatted color strings.

warning

If the input color cannot be parsed or converted to the specified output format, the processor will fail unless ignore_failure is set to true. Invalid color names or malformed color values will trigger errors.

Examples

Hex to RGB Conversion

Converting hexadecimal color to RGB format...

{
"color_value": "#ff5733"
}
- color_decode:
field: color_value
output_format: rgb
target_field: rgb_color

converts to RGB notation:

{
"color_value": "#ff5733",
"rgb_color": "rgb(255, 87, 51)"
}

Named Color to Hex

Converting color name to hexadecimal...

{
"ui_color": "red"
}
- color_decode:
field: ui_color
output_format: hex
uppercase: true

replacing the source value, since target_field defaults to field:

{
"ui_color": "#FF0000"
}

RGB to HSLA

Converting to an alpha-carrying format...

{
"theme_color": "rgb(100, 150, 200)"
}
- color_decode:
field: theme_color
output_format: hsla
target_field: hsl_color

the input carries no alpha, so the component is emitted as fully opaque:

{
"theme_color": "rgb(100, 150, 200)",
"hsl_color": "hsla(210, 48%, 59%, 1.00)"
}

Color to Array Format

Converting color to numerical array...

{
"brand_color": "#3498db"
}
- color_decode:
field: brand_color
output_format: rgb_array
target_field: color_values

outputs RGB as array:

{
"brand_color": "#3498db",
"color_values": [52, 152, 219]
}

Percentage RGB Output

Converting to RGB with percentage values...

{
"accent_color": "#80ff80"
}
- color_decode:
field: accent_color
output_format: rgb
percent_rgb: true
target_field: percent_color

outputs RGB as percentages:

{
"accent_color": "#80ff80",
"percent_color": "rgb(50.2%, 100.0%, 50.2%)"
}