Search code examples
javascriptnode.jsjsononedrive

Calling a JSON key that has a non-letter character


I am trying to return the value of @microsoft.graph.downloadUrl from the json object below:

[
  {
    '@microsoft.graph.downloadUrl': 'https://public.bl.files.1drv.com/XXXX',
    createdDateTime: '2021-07-10T06:14:31.03Z',
    cTag: 'QQQQ',
    eTag: 'SSSS',
    id: 'FFFF',
    lastModifiedDateTime: '2021-07-12T09:27:21.69Z',
    name: 'FILE_NAME',
    size: 98580,
    webUrl: 'https://1drv.ms/b/SSSS',
    reactions: { commentCount: 0 },
    createdBy: { application: [Object], user: [Object] },
    lastModifiedBy: { user: [Object] },
    parentReference: {
      driveId: 'XXX',
      driveType: 'personal',
      id: 'YYYY!YYY',
      name: 'Documents',
      path: '/drive/root:/Documents'
    },
    file: { mimeType: 'application/pdf', hashes: [Object] },
    fileSystemInfo: {
      createdDateTime: '2021-07-10T06:14:31.03Z',
      lastModifiedDateTime: '2021-07-12T09:27:21.69Z'
    }
  }
]

I wish to use something like this that i had done to extract the name as I need to be able to get the @microsoft.graph.downloadUrl from each json object (known as f below) in 'files'.

var fileName = (JSON.stringify(files[f].name));

I tried both:

var fileURL = (JSON.stringify(files[f]."@microsoft.graph.downloadUrl"));
var fileURL = (JSON.stringify(files[f][email protected]));

but neither work -- any help would be much appreciated!


Solution

  • You should just use files[f]["@microsoft.graph.downloadUrl"].