Nodes/LF Nodes/Get Value from JSON
ComfyUI Node

Get Value from JSON

Pluck a value out of a JSON blob without writing a single line of Python

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Get Value from JSON
  • json_input
  • ui_widget
  • json
  • string
  • number
  • int
  • float
  • boolean
key
index0

ComfyUI is a JSON machine under the hood - workflows are JSON, API responses are JSON, and the moment you wire in an LLM or a web API, you're holding a pile of it. The problem is ComfyUI's native graph doesn't give you an easy way to reach into an object and grab one field as a typed value. LF Nodes' JSON set exists to fix exactly that, and this is the "read" half.

LF_GetValueFromJSON takes a JSON object and a key, and hands you the value in whatever type you need - which is the entire trick. One output each for string, number, int, float, and boolean, plus the raw json output for when the value is itself a nested object or array. No casting nodes, no string surgery, no Python script node to babysit.

How it works

Feed it json_input (any node that emits JSON - an LLM response, a LoadLocalJSON, the output of a LF_SetValueInJSON) and the key you want. The index input covers the case where your JSON is actually a list of objects: set it to the position in the array you want to read from.

A typical use: you have an LLM that returns structured JSON like {"style": "noir", "subject": "detective", "lighting": "hard"}. Run that through here three times with keys style, subject, lighting, and each of those strings plugs straight into a prompt node or a text switch. That's the pattern the author himself showcases in the LF Nodes LoRA-testing workflows - generate structured metadata, then pull it apart visually in the graph.

A small reality check on the outputs: they're all derived from the same lookup, so they're not six different things - they're the same thing coerced to six types. If the value is 42, int gives you 42 and string gives you "42". Pick the one that matches what your downstream node expects; if a prompt node only takes a STRING, use string, not number.

The inputs that matter

Honestly, it's just two:

  • json_input - the object to search.
  • key - the field name. For nested paths you'll typically chain this node - grab the inner object with the json output, feed it to a second copy, and pull the leaf value.

The node renders a KUL_CODE widget that pretty-prints the JSON on the node body, which makes debugging "which key did I typo" dramatically less painful.

Installing it

From the LF Nodes pack - Manager, search LF Nodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/comfyui-lf

Restart ComfyUI and you're done; this pack ships precompiled with no extra deps. Note it's the legacy repo - the author migrated active work to lf-nodes, and this one is frozen but working.

Where people get burned

  • Key not found → the node errors out (or returns an empty value depending on version), and the error message isn't always obvious about which key failed. Check the pretty-printed JSON on the node body first.
  • A value that's actually a string of digits - "42" vs 42 - will still come out as text on the int output if the JSON stores it as a string. JSON semantics win over your hopes.
  • If you're using this with a list of objects, remember index defaults to 0, so you'll quietly always get the first object until you change it.

For anything where a workflow reads structured data, this is the node that stops you reaching for a code node. And if you need to write back too, its sibling LF_SetValueInJSON does the other half.

Category✨ LF Nodes/JSON

Inputs (4)

NameTypeDefaultDescription
json_inputJSONJSON Object.
keySTRINGKey to select.
indexINT0When the input is a list of JSON objects, it sets the index of the occurrence from which the value is extracted.
ui_widgetoptKUL_CODE

Outputs (6)

NameTypeDescription
jsonJSON
stringSTRING
numberNUMBER
intINT
floatFLOAT
booleanBOOLEAN