itchyny / gojq

Pure Go implementation of jq
MIT License
3.3k stars 119 forks source link

Add urid format string to decode URI values #213

Closed mnutt closed 1 year ago

mnutt commented 1 year ago

I noticed that while we have base64 encoding/decoding, jq can URI-encode but cannot URI-decode.

Given that it looks like gojq is open to making backwards-compatible improvements to jq, something like @urid would solve a use case I'm facing and provide parity with base64 encoding/decoding.

itchyny commented 1 year ago

Would you drop @ character in the commit message to prevent unexpected mentions on GitHub? Just like urid format string. Also, I'm interested in the use case you're facing and would like to know some jq queries utilizing the urid format string. Thanks.

mnutt commented 1 year ago

Sure thing. We're using gojq to let users transform incoming webhook payloads of arbitrary schemas from various third parties into common schemas. Some of them contain URI-encoded string values which they would like to decode. My best guess is that the third party wanted to allow unicode in titles but produce ASCII JSON.

{
  "properties": {
    "title": "Toshiba%202019%20Gen%205%20(11%22)"
    "url": "..."
  }
}
$ pbpaste | ./gojq ".properties.title | @urid"
"Toshiba 2019 Gen 5 (11\")"

(command line example, we would call this via the gojq API)