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 support for built-in function 'tostring' #72

Closed
kenjones-cisco opened this issue Sep 27, 2017 · 5 comments
Closed

Add support for built-in function 'tostring' #72

kenjones-cisco opened this issue Sep 27, 2017 · 5 comments

Comments

@kenjones-cisco
Copy link
Contributor

Add support for built-in function 'tostring'

The tostring function prints its input as a string. Strings are left unchanged, and all other values are JSON-encoded.
@b-dean
Copy link

b-dean commented Aug 9, 2023

@mikefarah, this says it was completed ages ago, but I cannot figure out how to do it. Nothing seems to know about tostring and it's not documented.

yq eval --null-input '1 | tostring'

produces:

Error: 1:5: invalid input text "tostring"

If this is complete, how are we supposed to use it?

@kro-cat
Copy link

kro-cat commented Mar 1, 2024

The tostring operator currently doesn't exist in yq. However, for future googlers, I found the @yaml encode filter ( or others like it, see encode-decode from the yq docs ) seems to work for my specific use case:

Expected result:

items:
  - object: |
      array:
        - |
          a: foo
          b: bar

yq filter:

{
  "items": [
    {
      "object": ({
        "array": [
          ({
            "a": (.path.to.foo),
            "b": "bar"
          } | @yaml)
        ]
      } | @yaml)
    }
  ]
}

@mikefarah
Copy link
Owner

Sorry, this was closed with a whole bunch of other cards that didn't have any traction - will reopen.

@mikefarah mikefarah reopened this Mar 4, 2024
mikefarah added a commit that referenced this issue Mar 4, 2024
@mikefarah
Copy link
Owner

Will be fixed in the next release

@mikefarah
Copy link
Owner

Fixed in v4.43.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants