diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-06-19 00:24:08 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-06-19 00:24:08 +0100 |
| commit | deeb507bfd23d4b547f49332ce216ff14db4308c (patch) | |
| tree | ecef14c607473b4dd5e36ebe47a770831f94508e | |
| parent | 736d9f8a23e48559cad7076851db1c1c5b891532 (diff) | |
Add jq.string_to_json
| -rw-r--r-- | jq.pyx | 6 | ||||
| -rw-r--r-- | tests/jq_tests.py | 8 |
2 files changed, 14 insertions, 0 deletions
@@ -1,3 +1,5 @@ +import json + cdef extern from "jv.h": ctypedef struct jv: pass @@ -55,6 +57,10 @@ def string_to_string(char* program, char* input): return "".join(results) +def string_to_json(char* program, char* input): + return json.loads(string_to_string(program, input)) + + cdef process(jq_state *jq, jv value): cdef int jq_flags = 0 diff --git a/tests/jq_tests.py b/tests/jq_tests.py index 0bef31f..0442459 100644 --- a/tests/jq_tests.py +++ b/tests/jq_tests.py @@ -25,3 +25,11 @@ def output_elements_are_separated_by_newlines(): "1\n2\n3", jq.string_to_string(".[]", "[1,2,3]") ) + + +@istest +def string_to_json_parses_json_output(): + assert_equal( + [1, 2, 3], + jq.string_to_json("[.[]]", "[1,2,3]") + ) |
