1. Ken Smith
  2. JsonNetDecycle

Overview

HTTPS SSH

JsonNetDecycle

This is a very simple TypeScript/JavaScript library that can be used to re-establish object references removed by Json.NET. It's based on the cycle.js library by Douglas Crockford, but uses the non-standard reference style used by Json.NET instead of the IETF draft proposal for JSON references.

Before you ask, yes, it would probably be better if Json.NET adopted the IETF proposed standard. But some of us need to get work done before that is likely to happen.

You use it kinda like this:

var room = {
    "$id": "57",
    "Name": "_default",
    "User": {
        "$id": "58",
        "UserTag": "ken",
        "Sessions": [{
            "$id": "59",
            "SessionId": "0ca7474e-273c-4eb2-a0c1-1eba2f1a711c",
            "User": {
                "$ref": "58"
            },
            "Room": {
                "$ref": "57"
            }
        }],
    },

    "Sessions": [{
        "$ref": "59"
    }]
};
JsonNetDecycle.retrocycle(room);
alert(room.Sessions[0].User.UserTag);

It's in TypeScript because TypeScript is awesome. But since TypeScript compiles down to JavaScript, folks who haven't yet seen the light should still be able to use it.