Hi,
I see that you are trying to parse a huge json file using MATLAB.
This can be done using 'jsondecode' and 'jsonencode' functions as below:
After extracting the contents of the zip file - https://www.elections.alaska.gov/results/22SSPG/CVR_Export_20220908084311.zip , many json files are available in the extracted folder. Among them, we will parse the largest json file - 'CvrExport.json' of size 364MB using the MATLAB code below. The below code stores the decoded json data into the 'data' variable, Further, the code also properly formats the json data and then writes to the file - 'output.json'. jsonStr = fileread('CvrExport.json');
data = jsondecode(jsonStr);
fid = fopen('output.json', 'w');
fprintf(fid, '%s\n', jsonencode(data, PrettyPrint=true));
Now, we can parse one field at a time using the dot operator as below.
ElectionId: '2022 Primary Election and Special General'
Sessions: {192289×1 cell}
ImageMask: 'D:\NAS\2022 Primary Election and Special General\Results\Tabulator91100\Batch001\Images\91100_00001_000001*.*'
VotingSessionIdentifier: ''
UniqueVotingIdentifier: ''
Similarly, the json can be further parsed into the the 'Original' field.
The 2nd problem you mentioned is being unable to view the json file in a text editor. This will be a problem for the 'output.json' file too since it is also a huge file. You can have a work around for this by viewing a few lines at a time. For example, the following MATLAB script displays the first 200 lines of the 'output.json' file.
fid = fopen('output.json', 'r');
You can also view line by line of the huge output.json file using the 'more' command in the 'Windows Command Prompt Window (CMD)'. You may check the output below:
"ElectionId": "2022 Primary Election and Special General",
"ImageMask": "D:\\NAS\\2022 Primary Election and Special General\\Results\\Tabulator91100\\Batch001\\Images\\91100_00001_000001*.*",
"VotingSessionIdentifier": "",
"UniqueVotingIdentifier": "",
"PrecinctPortionId": 404,
"OutstackConditionIds": [],
You may refer here for documentation of the 'jsondecode' and 'jsonencode' functions:
- https://www.mathworks.com/help/matlab/ref/jsondecode.html
- https://www.mathworks.com/help/matlab/ref/jsonencode.html
Hope this helps in resolving your query!