예제 #1
0
    def filter(self, data, subfilter):

        try:
            jsondata = json.loads(data)
        except ValueError:
            raise ValueError('The url response contained invalid JSON')

        if 'query' not in subfilter:
            raise ValueError('{} filter needs a query'.format(self.__kind__))

        if jq is None:
            raise ImportError('Please install jq')

        return jq.text(subfilter['query'], jsondata)
예제 #2
0
    def text_function_with_json_text_input_returns_all_output_elements_as_string(
            self):
        output = jq.text(".[] + 1", text="[1, 2, 3]")

        assert_equal("2\n3\n4", output)
예제 #3
0
def transform_with_jq(json_input: str, jq_filter: str) -> str:
    """Apply a jq filter on raw json input, outputs raw json (may be on several lines)"""
    return jq.text(jq_filter,
                   json.loads(json_input))  # type: ignore[no-any-return]