I'm using the JSON.NET serializer with Entity Framework and have run into a situation where the JSON being outputted has these "special properties" included such as $id
and $ref
. From what I've read, these properties are used by pure JSON to condense the JSON outputted so that the repeated element does not have to be written twice.
So, the JSON that gets outputted is something like this:
var myArray = [
{
"ActiveStates": [
{
"$id": "1",
"StateID": "CA",
"Name": "California"
},
{
"$id": "2",
"StateID": "NV",
"Name": "Nevada"
}
],
"DefaultState": {
"$ref": "1"
}
}
];
Using Javascript, how can I use the $ref
from DefaultState and $id
from AvailableStates to return the Name
of California
?
I'm thinking something with logic similar to myArray.find(myArray.DefaultState.$ref).Name;
which might return California
.
Hopefully this is something easy like this.
EDIT: I would also consider it an acceptable answer to learn how to disable these "special properties" from being rendered to the array even if it means that the JSON outputted will be longer due to the duplicated elements.