|
| 1 | +# JUON |
| 2 | + |
| 3 | +JUON is short for JS URL Object Notation. |
| 4 | +Think of it as JSON values for URLs. |
| 5 | +That means the syntax does not use characters that are not safe to use in URLs. |
| 6 | + |
| 7 | +It is not only inspired by JSON but designed to be easily |
| 8 | +translatable to JSON. For that, it shares the same types: |
| 9 | +_object_, _array_, _string_, _number_, _boolean_ and _null_. |
| 10 | + |
| 11 | +Where possible the JSON syntax was kept in JUON. |
| 12 | +This should help both translate but also remember the syntax for everyone |
| 13 | +already familiar with JSON. |
| 14 | + |
| 15 | +The key syntax differences are: |
| 16 | + |
| 17 | +* object and arrays both use round brackets `(...)` |
| 18 | +* strings are quoted in single upticks `'...'` |
| 19 | +* positive numbers or positive exponents must not use `+` (omit it) |
| 20 | +* object member names are not quoted |
| 21 | +* object member names can only use `A-Z a-z 0-9 - . _ @` |
| 22 | +* object member names must start with a letter or `@` |
| 23 | +* empty array is `()`, empty object cannot be expressed (approximate with `null`) |
| 24 | +* as strings are quoted with single upticks `"` does not need escaping |
| 25 | + but instead `'` is escaped as `\'` |
| 26 | + |
| 27 | +Furthermore, JUON is more "lenient" than JSON both to be more user-friendly and |
| 28 | +to allow shorter URLs though the use of shorthands and omissions: |
| 29 | + |
| 30 | +* `null` can be encoded as the empty string or shortened to `n` |
| 31 | +* `true` can be shortened to `t` |
| 32 | +* `false` can be shortened to `f` |
| 33 | +* numbers can start with `.` (= `0.`) |
| 34 | +* numbers can end with `.` (= `.0`) |
| 35 | + |
| 36 | +In summary, JUON can express everything JSON can, except the empty object `{}`. |
| 37 | +Some characters in strings obviously will need URL encoding to be allowed in URLs. |
| 38 | + |
| 39 | +## Example |
| 40 | +Here is a JSON example: |
| 41 | +```json |
| 42 | +{ |
| 43 | + "name": "Freddy", |
| 44 | + "age": 30, |
| 45 | + "car": null, |
| 46 | + "addresses": [{ |
| 47 | + "street": "Elm Street", |
| 48 | + "zip": 1428, |
| 49 | + "city": "Springwood", |
| 50 | + "invoice": true |
| 51 | + }] |
| 52 | +} |
| 53 | +``` |
| 54 | +In JUON the equivalent Java `String` would be (formatting whitespace removed): |
| 55 | +``` |
| 56 | +(name:'Freddy',age:30,car:null,addresses:((street:'Elm Street',zip:1428,city:'Springwood',invoice:true))) |
| 57 | +``` |
| 58 | +This could be further shortened by using shorthands and omitting `null` values: |
| 59 | +``` |
| 60 | +(name:'Freddy',age:30,car:,addresses:((street:'Elm Street',zip:1428,city:'Springwood',invoice:t))) |
| 61 | +``` |
| 62 | +In a URL parameter the entire value would be URL encoded, resulting in: |
| 63 | +``` |
| 64 | +(name:'Freddy',age:30,car:,addresses:((street:'Elm+Street',zip:1428,city:'Springwood',invoice:t))) |
| 65 | +``` |
| 66 | +(Note: the `+` could also be `%20`) |
| 67 | + |
| 68 | + |
| 69 | +## Specification |
| 70 | + |
0 commit comments