I'm not sure what to do next with my JSON2Apex generated output since I only need to see the values for three JSON keys. My generated output is approximately 300 lines long and below is a snippet of two types of JSON output that I would receive and parse through.
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')/drive/root/children",
"value": [
{
"createdDateTime": "2018-06-04T20:30:42Z",
"eTag": "\"{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx},1\"",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"lastModifiedDateTime": "2018-06-04T20:30:42Z",
"name": "Al's Files",
"webUrl": "https://example.sharepoint.com/sites/it/Shared%20Documents/Al%27s%20Files",
"cTag": "\"c:{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx},0\"",
"size": 6566266651,
"createdBy": {
"user": {
"email": "[email protected]",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8",
"displayName": "Roger Kilo"
}
},
"lastModifiedBy": {
"user": {
"email": "[email protected]",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"displayName": "Roger Kilo"
}
},
"parentReference": {
"driveId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"driveType": "documentLibrary",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"path": "/drive/root:"
},
"fileSystemInfo": {
"createdDateTime": "2018-06-04T20:30:42Z",
"lastModifiedDateTime": "2018-06-04T20:30:42Z"
},
"folder": {
"childCount": 1
}
},...
{
"@microsoft.graph.downloadUrl": "https://example.sharepoint.com/sites/it/_layouts/15/download.aspx?UniqueId=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&Translate=false&tempauth=eyAB4AiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvaGFub3ZlcnJlc2V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eTag": "\"{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx},3\"",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"lastModifiedDateTime": "2018-04-04T16:14:30Z",
"name": "Mike Roger Plan.doc",
"webUrl": "https://example.sharepoint.com/sites/it/_layouts/15/Doc.aspx?sourcedoc=%7BB307014A-13EF-4A86-8C16-B2876C141B40%7D&file=Mike%20Roger%20Plan.doc&action=default&mobileredirect=true",
"cTag": "\"c:{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx},3\"",
"size": 683008,
"createdBy": {
"user": {
"email": "[email protected]",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"displayName": "Roger Kilo"
}
},
"lastModifiedBy": {
"user": {
"email": "[email protected]",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"displayName": "Delta Foxtrot"
}
},
"parentReference": {
"driveId": "bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"driveType": "documentLibrary",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"path": "/drive/root:"
},
"file": {
"mimeType": "application/msword",
"hashes": {
"quickXorHash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"fileSystemInfo": {
"createdDateTime": "2018-01-24T15:25:21Z",
"lastModifiedDateTime": "2018-04-04T16:14:30Z"
}
},...
}
Since I need only the values for "name", "childCount" under "folder" tag, and "mimeType" under the "file" tag, would I need to add all 300+ lines to my script, or would I just take out what I need and not worry about the rest like below?
public class JSON2Apex {
public class Folder {
public Integer childCount {get;set;}
public Folder(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'childCount') {
childCount = parser.getIntegerValue();
} else {
System.debug(LoggingLevel.WARN, 'Folder consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
public class File {
public String mimeType {get;set;}
public Hashes hashes {get;set;}
public File(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'mimeType') {
mimeType = parser.getText();
} else if (text == 'hashes') {
hashes = new Hashes(parser);
} else {
System.debug(LoggingLevel.WARN, 'File consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
public class Value {
public Folder folder {get;set;}
public File file {get;set;}
}
public Value(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
public class Folder {
public Integer childCount {get;set;}
}
public Folder(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'childCount') {
childCount = parser.getIntegerValue();
} else if (text == 'folder') {
folder = new Folder(parser);
} else if (text == '@microsoft.graph.downloadUrl') {
@microsoft_graph_downloadUrl = parser.getText();
} else if (text == 'file') {
file = new File(parser);
} else {
System.debug(LoggingLevel.WARN, 'Folder consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
I'm also unsure as to how to reference the generated output to find all the values for each parsed type and add them to an array for later processing. Could someone explain this better or point me in the right direction?