News for hackers. Stuff that matters.
Re:JSON5 – JSON for Humans by milch on Sunday December 08, 2024 @10:56PM (#42362955)
I've also seen parser directives inserted into the keys like `{ "fooBar__datetime": 123456780.0 }`, and many other creative workarounds
Re:JSON5 – JSON for Humans by mmis1000 on Monday December 09, 2024 @12:55AM (#42363385)
Actually there is a common practice that java or js library used to serialize typed data.

They just preserve the key starts with $ for special use

So a class A with a double and and an int field will be something like

  {
    "$type": "A"
    "value":{
      "a": {
        "$type": "double",
        "value": 1
      },
      "b": {
        "$type": "int",
        "value": 2
      }
    }
  }
And what about keys that actually starts with $?

You just escape it with special $raw key

  "$raw": {
    "$escaped": {
      "$type": "double",
      "value" 1
    }
  }
It's a bit way too verbose. But given it is just a serialization format inside some library or app, it won't cause too much problems.