# Programmatic Workflow JSON Modification When modifying multiple LTX workflow JSONs with the same changes (sampler, duration, imageFile, prompt), use a Python script rather than manual JSON editing. This avoids quoting errors in shell heredocs and ensures consistent modifications across clips. ## Pattern 1. Write the modification script locally (on Hermes host) 2. scp it to .202 3. Run it via SSH ## Example: build_clips.py (2026-07-22) ```python import json # Load templates c1 = json.load(open("/tmp/api_cyberpunk_C1.json")) c2 = json.load(open("/tmp/api_cyberpunk_C2.json")) # Common modifications for both clips for d, name in [(c1, "C1"), (c2, "C2")]: p = d["prompt"] # Node 20: sampler p["20"]["inputs"]["sampler_name"] = "euler_ancestral_cfg_pp" # Node 131: duration -> 121 frames / 5.04s p["131"]["inputs"]["duration_frames"] = 121 p["131"]["inputs"]["end_frame"] = 121 p["131"]["inputs"]["duration_seconds"] = 5.04 p["131"]["inputs"]["end_second"] = 5.04 # Node 131 timeline_data td = json.loads(p["131"]["inputs"]["timeline_data"]) td["normalDurationFrames"] = 121 seg = td["segments"][0] seg["length"] = 121 seg["end"] = 5.04 # C1-specific: boss pan right p1 = c1["prompt"] td1 = json.loads(p1["131"]["inputs"]["timeline_data"]) td1["segments"][0]["imageFile"] = "ltx_boss_A.png" td1["segments"][0]["prompt"] = "..." # full prompt p1["131"]["inputs"]["timeline_data"] = json.dumps(td1) # C2-specific: frame-B -> woman reveal p2 = c2["prompt"] td2 = json.loads(p2["131"]["inputs"]["timeline_data"]) td2["segments"][0]["imageFile"] = "ltx_boss_B.png" # CRITICAL: pre-rendered empty frame B td2["segments"][0]["prompt"] = "..." # full prompt p2["131"]["inputs"]["timeline_data"] = json.dumps(td2) # Write both json.dump(c1, open("/tmp/api_boss_C1_fixed.json", "w"), indent=2) json.dump(c2, open("/tmp/api_boss_C2_fixed.json", "w"), indent=2) ``` ## Why Not Shell Heredocs? Shell heredocs with Python inside them have quoting issues: - Single quotes inside the Python string break the heredoc delimiter - Multi-line prompts with special characters get mangled - Escaping is fragile and error-prone The scp + remote execution pattern avoids all of this. ## Dispatch ```bash # Write script locally write_file /tmp/build_clips.py # scp to .202 and run sshpass -p 'passw0rd' scp /tmp/build_clips.py n8n@10.0.0.202:/tmp/build_clips.py sshpass -p 'passw0rd' ssh n8n@10.0.0.202 'python3 /tmp/build_clips.py' ```