Custom @escape functions
Something like this?
gojq.Compile(
query,
gojq.WithEscaper("goprint", func(x any) string {
return fmt.Sprint(x)
}),
)
$ "abcde" | split("") |
@json "json: \(.)",
@sh "sh: \(.)",
@goprint "goprint: \(.)"
json: ["a","b","c","d","e"]
sh: 'a' 'b' 'c' 'd' 'e'
goprint: [a b c d e]
For reference, jaq implements it like this:
$ jaq -n 'def @upcase: ascii_upcase; "world" | @upcase "hello \(.)"'
"hello WORLD"
For reference, jaq implements it like this:
$ jaq -n 'def @upcase: ascii_upcase; "world" | @upcase "hello \(.)"' "hello WORLD"
Pretty cool - although at that point, I think we may as well just redefine the @foo syntax to be syntactic sugar for a normal function call:
-"world" | @upcase "hello \(.)"
+"world" | "hello \(. | upcase)"
@myaaaaaaaaa now jqjq does it the same way at jaq 🥳 but as you say even more general would be nice but then would we extend the the standard library with all the existing formats as functions minus the "@"? 🤔
but then would we extend the the standard library with all the existing formats as functions minus the "@"? 🤔
Yes, that would be one of the pitfalls of this method - mainly the redundant text - tostring and json - tojson functions.