Skip to content

URL safe object notation dialect #58

Closed
@jbee

Description

@jbee

Summary

Following the idea of using a JSON inspired notation for complex values in URLs (see https://github.com/Nanonid/rison ) and considering that the following characters are safe to use in URLs...

 A-Z a-z 0-9 - . _ ~ ( ) ' ! * : @ , ;

...the following modifications could be made to standard JSON to create a URL safe object notation that easily can be transcribed to JSON while providing a more user friendly surface notation:

  • member properties are restricted to A-Z a-z 0-9 - . _ @ but must start with a letter or @
  • member properties are not quoted
  • numbers can only be given in simple integer and floating point notation (no exponent notation)
  • positive numbers must not use +
  • string literals use single quotes '...'
  • string escaping works the same except the escaped "end of literal" \" becomes \'
  • objects and arrays use round brackets instead of square or curly; (...); () is the empty array; empty objects are omitted

The literals stay

  • true => true
  • false => false
  • null => null

Motivations and Goals

  • URL safe syntax that leans on URL encoding for special characters in string literals
  • keep the notation very close to JSON so users can remember and apply a few simple rules of how to convert it in their mind
  • allow in-place transcription to JSON; that means the notation uses the same length (or more) symbols

Example

JSON

{
  "name": "John",
  "age": 42,
  "license": false,
  "keywords": ["hello", "world"]
}

URL Object Notation

(name:'John',age:42,license:false,keywords:('hello','world'))

Array vs Object

It certainly is not ideal to parse the notation when both objects and arrays use round brackets. But since round brackets are the only URL safe type of brackets this is the most user friendly option. This means the parser potentially needs more look-ahead then JSON would require. However, since property names are not quoted but start with a letter there is only a small clash when the first letter is t, f or n. In that case this may be atrue, false, null literal or the start of a property. Only in those cases the parser needs to read-ahead and see if a , or : is found first.

The only case where array and object become indistinguishable is the empty array vs the empty object.
As empty objects are usually equivalent to "no property is defined" () should only be used for the empty array
while empty objects should simply left out.

URL Encoding

As this notation is intended to be used for complex value specified as URL parameter value the URL decoding will be applied to the entire value in one operation. This should make it obvious that the encoding equally can and should be applied to the entire value. Therefore it should also be obvious that white-space can occur like it can in JSON but that it will look ugly when looking at the URL encoded value.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions