Skip to content

Advanced Key Syntax

0xMaxLab edited this page Mar 16, 2026 · 7 revisions

Description

Let us summarize all JSON key features:

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

The Constructor called and joined with the given object:
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 object is joined as well:
{ "key::$ref:path/to/object, $file:path/to/file, ... <commands>": { ... } }

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 $clone does, check out this page.

import * as RichJson from "@rjson/parser"

class Coord2() {
     x = 0;
     y = 0;
		
     length_xy = function() { return sqrt(x * x + y * y); }
}
RichJson.addClassMapping("Coord2", Coord2);

{
     "some_object": {
         "y": 10
     },

     "$clone:example1=Coord2": {
         "x": 20,
         "y": 20
     },
     "$clone:example2=Coord2::some_object": {
         "x": 20
     }
}

After Apply

Note

No late applyment features were used here, except for the $clone command.

{
     "some_object": {
         "y": 10
     },

     "example1": { // "$clone:example1=Coord2"
         "x": 20,
         "y": 20,
         "length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
     },
     "example2": { // "$clone:example2=Coord2::some_object"
         "x": 20,
         "y": 10,
         "length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
     }
}

Author’s Recommendation: next read: Late Applying

Clone this wiki locally