Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jq_raw function to simplexpr #952

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RomanHargrave
Copy link

@RomanHargrave RomanHargrave commented Oct 21, 2023

Description

This is a fairly simple change which adds a jq_raw function - jq_raw() shares jq()'s implementation, with the difference being that top level strings are not quoted (nested strings are quoted). This behavior is consistent with jq's documented and observed behavior for --raw-output.

This PR resolves #745.

For instance, we see the following behavior with orthodox jq

$ echo '{"a": ["b"]}' | jq -r '.a'
[
  "b"
]
$ echo '{"a": ["b"]}' | jq -r '.a[]'
b

Similarly, the expressions

{jq_raw("{\"a\": [\"b\"]}", ".a")}
{jq_raw("{\"a\": [\"b\"]}", ".a[]")}

Produce the following output,

image

Usage

Use jq_raw as you would jq when unquoted strings are needed (typically for display)

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/src directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

jq_raw() shares the jq()'s implementation, with the difference being
that _top level_ strings are not quoted (nested strings are quoted).
This behavior is consistent with jq's documented and observed behavior
for --raw-output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add option to return jq command with raw output
1 participant