Currently, we can't serialize an object with a property called $ref. Well, we can, but it will get interpreted as a reference when it's deserialized and things will break. In order to be able to serialize/deserialize ANY JSON-compatible value, we need a way to escape a $ref that isn't a reference. I think it could work to escape any property name with a leading $ as $$.
| original |
serialized |
deserialized |
| { "$ref": "foo" } |
{ "$$ref": "foo" } |
{ "$ref": "foo" } |
| { "$$ref": "foo" } |
{ "$$$ref": "foo" } |
{ "$$ref": "foo" } |
We could be more specific than every leading $, but the rule starts to get more complicated. It would have to be any number of leading $s followed by ref. I suppose that's fairly easy to implement and should be fairly efficient with a regular expression.
if (/^\$+ref$/.test(propertyName)) {
propertyName = "$" + propertyName;
}
An back,
if (/^\${2}ref$/.test(propertyName)) {
propertyName = propertyName.slice(1); // That would be propertyName[1:] in Python if I remember correctly. (do slices work on strings or just lists?)
}
Currently, we can't serialize an object with a property called
$ref. Well, we can, but it will get interpreted as a reference when it's deserialized and things will break. In order to be able to serialize/deserialize ANY JSON-compatible value, we need a way to escape a$refthat isn't a reference. I think it could work to escape any property name with a leading$as$$.We could be more specific than every leading
$, but the rule starts to get more complicated. It would have to be any number of leading$s followed byref. I suppose that's fairly easy to implement and should be fairly efficient with a regular expression.An back,