Skip to content

Advanced Key Syntax

Hawkmax edited this page Oct 10, 2025 · 17 revisions

Description

Let us summarize all JSON key features:

A simple RichJSON command that takes a struct as input:
"#<command_name>:key": { ...params... }

The Constructor called and joined with the given struct:
normal: { "key=<class_name>": { ... } }
late: { "key==<class_name>": { ... } }

Inheritance is basically a concatenation of RichJSON commands.
They are joined from left to right, and finally the given struct is joined as well:
{ "key::#ref:path/to/struct, #file:path/to/file, ... <commands>": { ... } }

Interfaces allow you to implement multiple interfaces at once, applied from left to right:
normal: { "key;MyInterface1, MyInterface2, ... <interfaces>": { ... } }
late: { "key;;MyInterface1, MyInterface2, ... <interfaces>": { ... } }

Using Features Together

And now what?

It’s not a coincidence that these features are listed here because yes, you can use them all at once.
But be careful: these features can only be combined in the correct order.
Let me give you some examples:

Examples

Before Apply

Important

If you want to know what #twin does, check out this page.

function Coord2() constructor {
     x = 0;
     y = 0;
		
     length_xy = function() { return sqrt(sqr(x) + sqr(y)); }
}

function ILoggable() constructor {
    
    ctor {
        __log_string = undefined;
    }

    get_log_string = function() {
        if (__log_string == undefined) 
            __log_string = $"{MY_CLASS_NAME} {some_variable} {some_status}";
        
        return __log_string;
    }
}

{
     "some_struct": {
         "y": 10
     },

     "#twin:example1=Coord2": {
         "x": 20,
         "y": 20
     },
     "#twin:example2=Coord2::some_struct": {
         "x": 20
     },
     "example3=Coord2::some_struct;ILoggable": {
         "x": 20
     }
}

After Apply

Note

No late applyment features were used here, except for the #twin command.

{
     "some_struct": {
         "y": 10
     },

     "example1": { // "#twin:example1=Coord2"
         "x": 20,
         "y": 20,
         "length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
     },
     "example2": { // "#twin:example2=Coord2::some_struct"
         "x": 20,
         "y": 10,
         "length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
     },
     "example3": { // "example3=Coord2::some_struct;ILoggable"
         "x": 20,
         "y": 10,
         "length_xy": function() { return sqrt(sqr(x) + sqr(y)); },
         "__log_string": undefined,
         "get_log_string": function() {
              if (__log_string == undefined) 
                  __log_string = $"{MY_CLASS_NAME} {some_variable} {some_status}";
        
              return __log_string;
         }
     }
}

Author’s Recommendation: next read: Late Applying

Clone this wiki locally