ComfyUI Node

JSON Generator

Build a JSON blob from scratch inside the graph

By Q-Bug4·Created 2 years ago·Updated about a year ago· 11
JSON Generator
    • generated_json
    key_value_pairs
    is_arrayfalse

    Everything else in Q-Bug4's JSON pack assumes you already have some JSON and want to read, patch, or walk through it. JSON Generator is the one that runs the other direction: you don't have JSON yet, you have some key/value pairs you want assembled into one. If you're building a request body for an API node, or a small structured record out of a few workflow values, this is how you get there without hand-typing a JSON string into a text widget and hoping you didn't miss a comma or a quote.

    How it works

    You give it key_value_pairs and it assembles them into a JSON structure - an object by default, or an array if you flip is_array on. It's the direct counterpart to JSONStringifierNode: that one turns an already-structured JSON value into a formatted string with layout controls (indent, key sorting); this one builds the structure in the first place from loose pairs you provide, with none of the manual bracket-and-quote bookkeeping.

    The inputs and outputs that matter

    • key_value_pairs - multiline string. This is where you list out what goes into the generated JSON.
    • is_array - BOOLEAN, defaults to false. Leave it off for a JSON object (the normal case - most APIs and configs expect {...} at the top level); flip it on if what you actually want out is a JSON array ([...]) instead.
    • generated_json (output) - the assembled JSON, as a STRING, ready to feed into anything downstream that expects a JSON blob - an API node's body field, JSONMergeNode to combine it with something else, or JSONModifierNode if you need to tweak one field of it later.

    Two inputs, one output - deliberately narrow. This node's whole job is turning "some values I have in the graph" into "one JSON string," nothing more.

    How to install it

    Look for "Simple JSON Parser" or "Json Node" in ComfyUI Manager; if it's not showing up, clone it directly:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Q-Bug4/Comfyui-Simple-Json-Node
    

    Restart ComfyUI. No dependencies, no model files - it's a pure string-manipulation node, so the install is as lightweight as this pack gets across the board.

    Common issues & troubleshooting

    Not sure whether to use this or just type JSON directly. If you already know exactly what the final JSON should look like and it's not going to change based on other node outputs, typing it directly into a multiline text widget and feeding that straight to JSONParserNode or wherever it's headed is honestly simpler - you skip a node. JSONGeneratorNode earns its place when the values going into the JSON are themselves coming from elsewhere in the graph (a seed, a filename, a value another node computed), and you want ComfyUI to assemble the structure rather than you hand-formatting a string every time an upstream value changes.

    Output isn't valid JSON, or a downstream node rejects it. This is the least-used node in the pack by a wide margin (it barely registers any search traffic compared to the parser or the iterators), which likely means fewer people have hit its edge cases and reported them - so if generated_json comes out malformed for a shape you're trying, test the raw output with JSONParserNode (empty path) before wiring it further downstream, rather than assuming the generator handled your input the way you expected.

    Nested structures. The README doesn't document a syntax for building nested objects or arrays-within-objects through key_value_pairs directly - this node is scoped to a flat set of pairs. If you need genuine nesting, the more reliable path is generating the flat pieces here and stitching them together with JSONMergeNode or JSONModifierNode, rather than trying to force a deep structure out of one generator call.

    Small, single-purpose node - the value is entirely in not hand-typing JSON syntax when the values are already floating around your graph.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    key_value_pairsSTRING
    is_arrayBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    generated_jsonSTRING