ComfyUI Node

JSON Modifier

Patch one field of a JSON blob without rebuilding the whole thing

By Q-Bug4·Created 2 years ago·Updated about a year ago· 11
JSON Modifier
    • modified_json
    json_input
    path
    new_value

    Say you've got a JSON config sitting in your graph - maybe an API request body, maybe a saved preset - and you want to change one field before it goes anywhere, without hand-editing the whole string or rebuilding it from scratch. That's the entire job of JSON Modifier: point it at a path inside a JSON blob, hand it a new value, and it gives you back the same JSON with just that one spot changed. It's the write counterpart to JSONParserNode's read.

    How it works

    Same path syntax as the rest of this pack - dot notation for nested objects (object.nestedObject.property), bracket or dot indexing for arrays (array[0] or array.0), and you can chain them (object.array[2].property). The node walks the JSON down to that path and replaces whatever's there with new_value, then hands back the whole structure, modified, as a string. Everything else in the JSON is left alone - you're not reconstructing the object, just patching one location in it.

    The inputs and outputs that matter

    • json_input - multiline string, the JSON you're modifying.
    • path - where in that JSON to write. Same syntax as the parser node.
    • new_value - multiline string, what goes at that path.
    • modified_json (output) - the whole JSON, with your change applied, as a STRING.

    Three inputs, one output - this node does one thing and does it in one step. No separate "does this path exist" check built in, which matters below.

    How to install it

    Look for "Simple JSON Parser" or "Json Node" in ComfyUI Manager; if it's not there for you, do it manually:

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

    Restart ComfyUI. No requirements file, no models, nothing to download - the whole pack is Python dict manipulation, so this is as close to a zero-cost install as custom nodes get.

    Common issues & troubleshooting

    Invalid path throws instead of creating the field. This is the thing that trips people up most: JSONModifierNode modifies an existing path, and the README's own error-handling section lists invalid paths as a ValueError. If you're expecting this node to create a brand-new key that doesn't exist yet in the source JSON, test that assumption first - if it errors on a path you thought was new, the path probably needs to already exist in some form (even as null or an empty value) before you can write to it. If you're building JSON from nothing, reach for JSONGeneratorNode instead and skip the modifier entirely.

    new_value comes out as a string even when you wanted a number or boolean. Every field in this pack is a STRING type - inputs and outputs both - so whatever you type into new_value gets written in as text. If your downstream consumer expects "age": 31 as a JSON number and you write new_value as 31, check the actual serialized output rather than assuming; JSON-as-string manipulation in Python-land is a common spot for numbers to end up quoted when they shouldn't be.

    Type mismatches. Also called out directly in the README's error handling - trying to index into a string as if it were an array, or into a plain value as if it had nested keys, raises rather than silently doing nothing. If your path assumes a shape the JSON doesn't actually have at that point (say, you're indexing [0] into something that turned out to be an object, not an array), you'll get an error, not a quiet no-op.

    Chaining multiple edits. There's no batch-modify - one node call, one path, one value. If you need to change three fields, that's three JSONModifierNodes in a row, each one's modified_json output feeding the next one's json_input. It's more wiring than a single multi-field patch would need, but it keeps each step legible, which for a small utility pack like this is arguably the right trade.

    Categoryutils

    Inputs (3)

    NameTypeDefaultDescription
    json_inputSTRING
    pathSTRING
    new_valueSTRING

    Outputs (1)

    NameTypeDescription
    modified_jsonSTRING