-
Notifications
You must be signed in to change notification settings - Fork 4
F♭ JSON
Jayson Harshbarger edited this page Apr 16, 2016
·
4 revisions
By definition of the following words F♭ is able to (mostly) parse a superset of JSON.
-
(
- start a quote -
)
- end a quote -
{
- start a quote -
}
- end a quote, convert to hash assuming a list of key value pairs[ key value key value ]
-
[
- start a lazy quote -
]
- start end a lazy quote -
:
- convert a string to an atom -
{word}:
- macro for creating atoms, same as"{word}" :
The following
{
"key": 10,
"key2": "20"
}
is interpreted by F♭ as:
{ "key" : 10 "key2" : "20" }
in other words:
- Start a quote
- Push a string
- Convert string to an atom
- Push a number
- Push another string
- Convert string to an atom
- push a string
- end the quote and convert to an hash assuming a list of key values pairs
resulting in the object:
{ key: 10, key2: '20' }
However, because this is actually F♭ the syntax is relaxed.
/* This is JSON.
JSON?
This is F♭! */
{
"key": 10, // This is a number
"key2": "20" // This is a string
}
{
"key": 10,
'key2': '20'
}
{
"key": 10
'key2': '20'
}
Quotes around keys are optional if the key is an atom (no whitespace is included between the key and colon)
{
key: 10
key2: '20'
}
Colon is optional between key and value if the key is a string.
{
"key" 10
"key2" '20'
}
{
key: 5 2 *
"key" 2 + : 10 10 + string
}
Including template strings
{
key: 5 2 *
`key$(1 1 +)` : `$(10 10 +)`
}
Including infinity, null, and complex values:
{
pi: 4 1 atan *
complex: 2 4 i * +
nothing: null
everything: 1 0 /
}
results in:
{ pi: 3.1415926535897932385
complex: 2+4i
nothing: Null
everything: Infinity }
{
a: [ 1 2 + ]
b: ( 1 2 + )
}
results in the object:
{
a: [ 1 2 + ]
b: [ 3 ]
}
- Introduction
- Language
- Words
- Internal
- Definitions
- Examples