I'm using the following library
To convert XML to JSON. After conversion console.log produces the following
{ '@':
{ RaceDayDate: '2012-03-15T00:00:00',
Year: '2012',
Month: '3',
Day: '15',
DayOfTheWeek: 'Thursday',
MonthLong: 'March',
IsCurrentDay: '1',
IsPresaleMeeting: '0',
ServerTime: '2012-03-15T19:48:47.840' },
PresaleRaceDate: [ { '@': [Object] }, { '@': [Object] }, { '@': [Object] } ],
Meeting:
[ { '@': [Object], Pool: [Object], Race: [Object] },
{ '@': [Object], Pool: [Object], Race: [Object] },
{ '@': [Object], Pool: [Object], Race: [Object] },
What does @ mean and assuming the data is stored in a variable named 'result' what is the syntax for accessing RaceDayDate, Year, Month etc? result.@ does not work
I'm using the following library
https://github.com/Leonidas-from-XIV/node-xml2js
To convert XML to JSON. After conversion console.log produces the following
{ '@':
{ RaceDayDate: '2012-03-15T00:00:00',
Year: '2012',
Month: '3',
Day: '15',
DayOfTheWeek: 'Thursday',
MonthLong: 'March',
IsCurrentDay: '1',
IsPresaleMeeting: '0',
ServerTime: '2012-03-15T19:48:47.840' },
PresaleRaceDate: [ { '@': [Object] }, { '@': [Object] }, { '@': [Object] } ],
Meeting:
[ { '@': [Object], Pool: [Object], Race: [Object] },
{ '@': [Object], Pool: [Object], Race: [Object] },
{ '@': [Object], Pool: [Object], Race: [Object] },
What does @ mean and assuming the data is stored in a variable named 'result' what is the syntax for accessing RaceDayDate, Year, Month etc? result.@ does not work
Share Improve this question asked Mar 15, 2012 at 9:54 HoaHoa 20.4k28 gold badges82 silver badges111 bronze badges 05 Answers
Reset to default 11'@'
is just a string like any other. In JavaScript, you can access it with
result['@']
Also note that the input is not valid JSON, as it is missing quotes around many dictionary keys and Object
, uses single instead of double quotes and ends with a comma.
As "Clarkeye" mentioned above I have one with “@” prefix for some tags (sample data given below). Those are attribute in the xml version of that message. I suspect conversion tool adding this prefix. json sample data
{
"@context": "\/v1\/contexts\/Book",
"@type": "Recipe",
"id": "12136",
"note": [
{
"@id": "\/v1\/terms\/331",
"@type": "SQL",
"id": 331,
"display": "SQL",
"taxonomy": "post_tag"
}
]
try result['@'].RaceDayDate
.
I'm not sure if this is relevant to this example, but I'm currently integrating with an API that allows you to pass either xml or json; in the json messages, any field that is stored as an attribute in the xml version of that message is prefixed with the '@' character - I assume that this is because the json is converted to xml for processing and whatever tool they are using for this uses @ to differentiate between elements and attributes.
It has no special meaning to JSON.
This particular data uses it as a key string. You'd have to know the meaning of the data to find out why.