Data structures and declaration
8th uses an enhanced version of the JSON standard for data declaration. It understands standard JSON, but allows a few extras to make things easier for the user
Declaring an array is as simple as
[ "cat", "dog", "rat" ]and declaring a map is just as simple:
{ "cat" : "feline", "dog" : "canine", "rat" : "murine" }or, alternatively:
{ cat: "feline", dog: "canine", rat: "murine" }
As you might expect, 8th allows you to mix different data types in each container (array or map), using the same JSON syntax you’re used to:
{ "foo" : "fighter", "bar" : [1,2,3] }
Where 8th strays from the JSON standard is in permitting comments within a data declaration:
{ "foo" : "fighter", \ Not much of a fighter "bar" : [1,2,3] }Besides comments, 8th also permits “words” (that is, functions) to be entered in the JSON, and inline interpreted code which may, when invoked, provide some calculated value for inclusion in an array or map.
Security measures
Allowing words inside JSON is a convenience for the programmer, but it could be a security vulnerability if a JSON string from an untrusted source were to be interpreted as-is. Therefore, 8th provides a word json> which converts only standard JSON.
If, on the other hand, the JSON came from a trusted source (for example, data the program itself saved), then it would be safe to use eval and gain the advantage of being able to take advantage of the “extras” 8th provides.