java-jq
java-jq copied to clipboard
how to give command-line options to jq (like --raw-output )?
Is there a way to pass command-line options to jq, e.g. --raw-output ? if so, how to? thanx
No there isn't yet, but it's something I plan to add.
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!
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.
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
I'd vote for this one too :)
👍 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);