plexus.cli.procedure.lua_dsl.primitives.json module

Json Primitive - JSON serialization/deserialization.

Provides: - Json.encode(data) - Serialize Lua table/value to JSON string - Json.decode(json_str) - Parse JSON string to Lua table

class plexus.cli.procedure.lua_dsl.primitives.json.JsonPrimitive(lua_sandbox=None)

Bases: object

Handles JSON encoding and decoding for procedures.

Enables workflows to: - Serialize Lua tables to JSON strings - Parse JSON strings into Lua tables - Handle data interchange with external systems

Initialize Json primitive.

Args:

lua_sandbox: LuaSandbox for creating Lua tables (optional)

__init__(lua_sandbox=None)

Initialize Json primitive.

Args:

lua_sandbox: LuaSandbox for creating Lua tables (optional)

decode(json_str: str)

Decode JSON string to Lua table.

Args:

json_str: JSON string to parse

Returns:

Lua table with parsed data

Raises:

ValueError: If JSON is malformed

Example (Lua):

local json_str = ‘{“name”: “Bob”, “scores”: [85, 92, 78]}’ local data = Json.decode(json_str) Log.info(“Decoded data”, {

name = data.name, first_score = data.scores[1]

})

encode(data: Any) str

Encode Lua data structure to JSON string.

Args:

data: Lua table or primitive value to encode

Returns:

JSON string representation

Raises:

ValueError: If data cannot be serialized to JSON

Example (Lua):
local user = {

name = “Alice”, age = 30, active = true

} local json_str = Json.encode(user) Log.info(“Encoded JSON”, {json = json_str}) – json_str = ‘{“name”: “Alice”, “age”: 30, “active”: true}’