Skip to content

Lens jq

πŸ€– AI-Generated Content

This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.

pyvider.components.functions.lens_jq

JQ lens function for JSON querying and transformation.

Classes

Functions

lens_jq

lens_jq(
    input_data: Any, query: str, *, lens: LensCapability
) -> Any

Applies a jq query and returns a native Python object.

Source code in pyvider/components/functions/lens_jq.py
@register_function(name="lens_jq", component_of="lens")
def lens_jq(input_data: Any, query: str, *, lens: LensCapability) -> Any:
    """Applies a jq query and returns a native Python object."""

    if not lens.is_enabled:
        raise FunctionError("The 'lens' capability is disabled in the provider configuration.")

    if not isinstance(query, str) or not query:
        raise FunctionError("The 'query' argument must be a non-empty string.")

    # Ensure input_data is converted to native Python before passing to JQ
    native_input_data = cty_to_native(input_data) if isinstance(input_data, CtyValue) else input_data

    try:
        result_cty = lens.jq(query, native_input_data)

        result = cty_to_native(result_cty)
        return result
    except Exception:
        raise