java-jq icon indicating copy to clipboard operation
java-jq copied to clipboard

how to give command-line options to jq (like --raw-output )?

Open HoffiMuc opened this issue 5 years ago • 6 comments

Is there a way to pass command-line options to jq, e.g. --raw-output ? if so, how to? thanx

HoffiMuc avatar Jul 11 '19 12:07 HoffiMuc

No there isn't yet, but it's something I plan to add.

arakelian avatar Jul 16 '19 17:07 arakelian

well, had to refactor to com.jayway.jsonpath:json-path now.

... but comparing the performance I can tell now, that your java-jq was considerably faster than parsing with json-path! ... so keep up the good work ... it's worth it!

HoffiMuc avatar Jul 17 '19 09:07 HoffiMuc

I'd like to vote for this enhancement too :) If sending arbitrary flags is too complicated, can we at least get --raw-output? Had a brief look through the code but I don't understand it enough to make the changes myself.

caciuc avatar Sep 07 '21 10:09 caciuc

Needing raw output is the first thing I ran into as soon as I used it in a real world setting. You can get around it by stripping the first and last characters off of the output. If implementing all command line options is going to take a while, it would be really helpful to just add an option for raw output. I think it might be implemented here https://github.com/arakelian/java-jq/blob/e9eb5465eec6e6323aa2b8e35ebae258590fc97e/src/main/java/com/arakelian/jq/JqLibrary.java#L300

solongtony avatar Sep 14 '22 22:09 solongtony

I'd vote for this one too :)

rakpawel avatar Nov 28 '22 15:11 rakpawel

👍 on this feature too, but as a workaround you can try use Jackson ObjectMapper to convert the JSON-encoded string into a regular String:

    JqLibrary library = ImmutableJqLibrary.of();
    JqRequest request = ImmutableJqRequest.builder()
      .lib(library)
      .input("{\"some-key\":\"some-value\"}")
      .filter(".\"some-key\"")
      .build();

    JqResponse response = request.execute();
    assertFalse(response.hasErrors());

    String outputRaw = response.getOutput();
    ObjectMapper objectMapper = new ObjectMapper();
    String output = mapper.readValue(outputRaw, String.class);
    assertEquals("some-value", output);

antonysouthworth-halter avatar Sep 15 '23 05:09 antonysouthworth-halter