How to Safely Access Nested Object Keys

:bullseye: Goal

Learn how to safely access nested object keys in Autom Mate without running into Variable usage error: Key not found.


:toolbox: When to Use

  • When working with JSON objects or structured data returned from connectors.

  • If some keys may be optional or missing.

  • To avoid null vs error inconsistencies between object[key] and object[key][subkey].


:rocket: Step-by-Step

  1. Direct Key Access

    • Accessing a top-level key:

      ##object[knownKey]##   β†’ returns value or null if not found   
      
  2. Nested Key Access

    • If the parent key exists but the subkey doesn’t, Autom Mate currently throws:

      Variable usage error. Key not found  
      
      
  3. Safe Checking with if and has property condition


:gear: Architecture / Flow

  • Without check β†’ object[key][subkey] β†’ throws error if key is missing.

  • With safe access β†’ staged lookup β†’ null returned instead of breaking execution.

object ──["key"]──┬── null  β†’ safe return
                  └── object ──["subkey"]──→ value / null


:white_check_mark: Validation

  • Test with an object missing the parent key: should not fail.

  • Test with a missing subkey under an existing parent: should return null safely.


:magnifying_glass_tilted_right: Troubleshooting

  • Error: Variable usage error. Key not found β†’ indicates direct nested access without validation.

  • Fix: Always check parent key existence before drilling deeper.


:light_bulb: Best Practices

  • Use intermediate variables to simplify nested lookups.

  • Apply has property condition before accessing deeper levels.

  • Treat null as an expected safe fallback, not an error.

1 Like