The Visitor (jq)
Project an external entity across a heterogeneous JSON matrix to harvest and alter.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Conjuration // Projection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
# The Visitor function applying operations based on type signatures
def data_visitor:
if type == "number" then . * 10
elif type == "string" then "VISITED: " + .
elif type == "array" then map(data_visitor)
elif type == "object" then map_values(data_visitor)
else . end;
# Injecting the visitor into the structure
.heterogeneous_payload | data_visitor
When a JSON structure is a chimeric beast of strings, arrays, and nested objects, hardcoding modifications is a path to madness. The Visitor algorithm traverses the heterogeneous tree. As it encounters each node, it evaluates the elemental type and applies a specific, external logic without ever modifying the underlying structural definitions.
Runic Tags:
#jq
#json
#transmutation
#gof