How to use jq.py
masterUsing jq.py follows a three-step workflow:
- Compile: Use
jq.compile(program_string)to compile a jq program. - Input: Call an input method on the compiled program to supply data.
- Output: Call an output method on the result to retrieve the processed data.
Using Arguments in Programs
You can pass predefined variables into your jq program using the args parameter in jq.compile().
Accessing the Program String
The original program string used for compilation is stored in the program_string attribute of the compiled program object.
import jq
# Standard workflow
program = jq.compile(".+5")
result = program.input_value(42).first()
assert result == 47
# Using arguments
program = jq.compile("$a + $b + .", args={"a": 100, "b": 20})
assert program.input_value(3).first() == 123
# Accessing program string
assert program.program_string == ".+5"