Quick answer: Use the JSON plugin’s path syntax: ".level.enemies.0.hp". Array indices are numbers, zero-based. Check Has Key before Get to avoid empty reads.
A level loader reads enemy stats from JSON. JSON.Get(“enemies.0.hp”) returns nothing. The path syntax is slightly off.
Path Syntax
The Construct 3 JSON plugin uses a dotted path from the root:
JSON.Get(".level.enemies.0.hp")
Lead with a dot for the root. Object keys are dotted; array indices are plain numbers (0, 1, 2…).
Guard with Has Key
JSON has key ".level.enemies.0.hp"
→ Set hp to JSON.Get(".level.enemies.0.hp")
Else
→ Set hp to 100 // default
Reading a missing path returns an empty value, not an error. Has Key lets you branch and supply defaults.
Iterating Arrays
Repeat JSON.ArraySize(".level.enemies") times:
Set idx to loopindex
Set hp to JSON.Get(".level.enemies." & idx & ".hp")
Build the path string with the loop index. ArraySize gives the count to repeat.
Set Path First
Some workflows use “Set current path” then relative gets. If you mix absolute and relative paths, you can get confusing misses. Pick one style.
Verifying
Load level JSON. Every enemy’s stats read correctly. Missing optional fields fall back to defaults instead of empty.
“Lead with a dot, numbers for array indices, Has Key before Get. The JSON plugin’s three rules.”
For big data files, validate the JSON structure once at load with a schema check — catch malformed content before it silently breaks gameplay.