DEV Community

Discussion on: What are best options for reliably parsed, yet powerful, querystrings?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Both JSON and YAML are heavily url-encoded.

I ended up with Rison, which only encode strings (to single quotes 'string') if needed. Also, arrays are !(a,1), instead of ["a",1].

But indeed, I know that the original Rison project is dead. 😒

  $axios.defaults.paramsSerializer = (params) => {
    return Object.entries<any>(params)
      .map(([k, v]) => {
        if (
          [
            '_',
            ...someTroublesomeKeys,
          ].includes(k) ||
          /^is[A-Z]/.test(k)
        ) {
          v = rison.encode(v)
        }

        return `${encodeURIComponent(k)}=${encodeURIComponent(v)}`
      })
      .join('&')
  }
Collapse
 
louy2 profile image
Yufan Lou

FYI, there is a better maintained fork: github.com/w33ble/rison-node