https://github.com/thevpc/tson
Typed & Smart Object Notation
https://github.com/thevpc/tson
Last synced: about 1 year ago
JSON representation
Typed & Smart Object Notation
- Host: GitHub
- URL: https://github.com/thevpc/tson
- Owner: thevpc
- Created: 2021-01-26T20:47:57.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-21T14:43:43.000Z (over 1 year ago)
- Last Synced: 2025-03-21T15:30:33.388Z (over 1 year ago)
- Language: Java
- Size: 2.02 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tson
Type Safe Object Notation
``tson`` (read Tyson) is a comprehensive, json-like format, that supports out of the box several simple and complex types.
``tson`` is ideal as a configuration format but can also be used as for communication (serialization).
Supported features include :
* string, single line/multiline
* null values and boolean type
* byte, short, int, long and bigint types
* float, double, bigdecimal types
* arrays, objects (maps)
* complex types (float, double and bigdecimal based complex values)
* arrays and matrices (of any other type)
* named arrays, parametrized arrays
* named objects, parametrized objects
* pairs (key/value)
* uplets
* names uplets (aka functions)
* annotations
* expressions with standard operators (+,-,*...)
* comments
# Rationale
Why not JSON. Well json does not support type safe primitives and is very limited. For instance it does not even support comments.
Why not YAML. YAML is a superset of json. So is ``tson``, however, unlike yaml, tson does not support space based syntax and hence
is less error prone. Besides, ``tson`` is ways more comprehensive and support ways more types and features.
``tson`` is also more user friendly with support of multiline strings, regular expressions, numeric values with units (think of 3GHz for three Giga Hertz for instance),
complex values, and so on.
# Some Examples
The following is tson example
```tson
// this is comment that prefixes a tson object
// tson object are very similar to json objects
{
/* an object entry can be anything, not only pairs*/
name:"some name"
// annotation can be applied to anything
@ThisIsMyAnnotation(something)
short-observation: ¶ this is a string that ends by line carriage
long-observation: """
this is a multiline string
"""
weight : 12.3kg // this is a double number with 'kg' suffix
full : 3L% // this is long number with '%' suffix
// tson object can also include non pair value like a number
3.141592
// objects can also be named (prefixed by a name)
parent: item{
(): "empty Uplet"
(1): "singleton"
}
// objects can also be parametrized
parent: item(name:"new item"){
(): "empty Uplet"
(1): "singleton"
}
// as does arrays
someArray: item(name:"new item")[
(): "empty Uplet"
"second item"
"third item"
]
}
```
The simplest ``tson`` file may contain a single literal, such as
```tson
12
```
or even a bar null value
```tson
null
```
``tson`` file may contain a more complex value such as
```tson
{
name:"some name",
value:12.3,
}
```
# Elements
## Primitive types
```
Byte : 12b , -12B , 0x12b, 0x12B, 012b, 0b011001b, 0b011001B
Short : 12s , -12S , 0x12s, 0x12s, 012s, 0b011001s, 0b011001S
Int : 120 , -122 , 0x123, 0x120, 0123, 0b0110011, 0b0110001
Long : 12L , -12L , 0x12L, 0x12L, 012L, 0b011001L, 0b011001L
(*) BigInt : 12G , -12G , 0x12G, 0x12G, 012G, 0b011001G, 0b011001G
Float : 1.0f, -1.2E-3F
Double : 1.0 , -1.2E-3 NaN -Inf +Inf +Bound -Bound
(*) Decimal : 1.0d , -1.2E-3D
(*) BigDecimal : 1.0c , -1.2E-3c
time : 12:11:00
date : 2022-12-11
datetime : 2022-12-11 12:11:00
boolean : true, false
null : null
```
## Strings
```
string : "Hello\n"
char : 'a'
simple string : 'some string'
regexp : /a*/
multiline string: """
some string
"""
```
## Array
```
array : [12, 13]
named array : someName[
12,
a:13
(1,2):[1, 2, 3]
]
named function array :
someName(a,b,c)[
12,
a:13
(1,2):[1, 2, 3]
]
```
## Uplet
```
(12, 13)
```
## Objects
```
object : {
12,
a:13
(1,2):[1, 2, 3]
}
named object : someName{
12,
a:13
(1,2):[1, 2, 3]
}
named function object :
someName(a,b,c){
12,
a:13
(1,2):[1, 2, 3]
}
```
## Annotation
```
@someAnnotation(a,b,c)
someName(a,b,c){
12,
a:13
(1,2):[1, 2, 3]
}
```
## Char Stream
```
^SomeDelimiter[ Anything you cna think of]SomeDelimiter
```
## Binary Stream
```
^SomeDelimiter[Base64]SomeDelimiter
```
## Alias
```
{
a: @(#ref)1234
b:&ref
}
```
## Comments
```
{ /*
this is a comment
*/
a:1234
b:&a
}
```
## Expressions
```
a+1
a=1
a:=1
a<=1
a==>1
a**1
a^1
```