Nodes/ComfyUI-SimpleChat/JSON -> Vars (Editable)
ComfyUI Node

JSON -> Vars (Editable)

Any JSON becomes {{mustache}} variables, flat or nested

By Moeblack·Created 9 months ago·Updated 7 months ago· 8
JSON -> Vars (Editable)
  • vars_in
  • vars
  • obj
json_text
strip_code_fencetrue
flatten_keystrue
prefix
override_modevars_in_overrides_json
overrides

The pack's chat nodes let you write {{var}} in any prompt, but where do the vars come from? JSON -> Vars (Editable) is the node that bridges the gap between "LLM gave me a JSON blob" and "my prompt references named variables." It takes any JSON object and converts it into a SIMPLECHAT_VARS dict, so {"character": "Aiko", "hair": "blonde"} becomes {{character}} and {{hair}} you can drop into prompts, system messages, or Mustache templates. It's the generic version of the fixed-schema unpacking the pack's Prompt JSON Unpack does.

The knobs

  • json_text - the JSON (fences auto-stripped via strip_code_fence).
  • flatten_keys (default on) - turns nested objects into dotted keys: {"character": {"hair": "blonde"}} becomes {{character.hair}}, and arrays become {{tags[0]}}. Turn it off and only top-level keys are exposed.
  • prefix - optional namespace, so anima makes {{anima.positive}}. Handy when you're merging multiple sources and don't want name collisions.
  • overrides - manual key=value lines (or key: value), applied last so you can pin or fix a value by hand.
  • override_mode - vars_in_overrides_json (default, incoming vars win over JSON) vs json_overrides_vars_in (JSON wins). Picks which side of the merge is boss.
  • vars_in - optional incoming vars to merge with.

Outputs: vars (the SIMPLECHAT_VARS dict) and obj (the parsed JSON as SIMPLECHAT_JSON for other consumers). The parser is forgiving - it strips fences, removes trailing commas, and as a last resort extracts the first {...} block from surrounding prose, which is exactly the messy output an LLM produces.

The workflow shape

Chat returns JSON → this node → vars into the next Chat node's vars input → that chat's prompt uses {{character}} freely. Or take a JSON from JSON Parse's obj port and turn it into template variables without re-parsing. Because prefix gives you namespacing, you can pipe an Anima prompt JSON in as anima.* while a settings JSON comes in unprefixed, and both coexist in one prompt.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/Moeblack/ComfyUI-SimpleChat

Restart, or use Manager and search "ComfyUI-SimpleChat". Only dep: aiohttp.

Gotchas

Values that are objects or arrays get stringified to JSON text when flattening is off - so {{tags}} with a list becomes ["a", "b"] in your prompt, not a comma-joined list. If you want readable joins, flatten on and reference {{tags[0]}} individually, or do the joining in the LLM before it outputs. And the top-level JSON must be an object; a bare array at the root raises "Expected a JSON object (dict) at top-level."

CategorySimpleChat/Utils

Inputs (7)

NameTypeDefaultDescription
json_textSTRING
strip_code_fenceBOOLEANtrue
flatten_keysBOOLEANtrueFlatten nested keys into a.b.c and arr[0] style keys.
prefixSTRINGOptional prefix, e.g. anima. (will become prefix.key)
override_modeCOMBOvars_in_overrides_json2 options: vars_in_overrides_json, json_overrides_vars_in
overridesSTRING
vars_inoptSIMPLECHAT_VARS

Outputs (2)

NameTypeDescription
varsSIMPLECHAT_VARS
objSIMPLECHAT_JSON