GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - alloc/json-qs: JSON in query strings, human-readable and compact

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
readme.md
readme.md
 
 
spec.md
spec.md
 
 
tsconfig.json
tsconfig.json
 
 
tsup.config.ts
tsup.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

json-qs

A query string encoder and decoder with full JSON compatibility, no wasteful repetition of keys, and minimal percent-encoding bloat.

Requirements

  • Must be human-readable.
  • Must be fully compatible with JSON.
  • Must not rely on percent-encoding. In other words, there must be zero ambiguity after URLSearchParams has decoded the query string.
  • Must have deterministic key order (for reliable caching).

Why make this?

The status quo for query strings is unfriendly to JSON objects and arrays, or at best, overly verbose with repeated keys. Also, backend developers are required to manually decode the string values into their intended types.

Okay, so why not avoid query strings for complex data, and just POST some JSON instead? Network-level caching of POST requests is not possible, so you'd need to implement your own application-level caching. By using GET with a query string, you can leverage the browser's built-in caching mechanism, as well as edge caching.

The json-qs approach is to keep query strings human-readable (unlike many others, who compress JSON to make it URI-safe) while still being fully compatible with JSON.

Specification

See the specification for more details or the test cases for examples.

Install

pnpm add @json-qs/json-qs

Encoding

import { encode } from '@json-qs/json-qs'

const params = encode({ a: { b: 0 } })
// => 'a={b:0}'

Decoding

Note that the json-qs decoder works in tandem with URLSearchParams, which is the standard JavaScript API for working with query strings. Percent encoding is handled by URLSearchParams, and json-qs simply ensures that the query string is fully compatible with JSON in a human-readable way.

import { decode } from '@json-qs/json-qs'

const url = new URL(request.url)
const params = decode(url.searchParams)

About

JSON in query strings, human-readable and compact

Topics

jsonquerystringspecification

Resources

Readme
MIT license
Activity
Custom properties

Stars

25 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.