I am trying to read objects within a json file but I seem to have gotten stuck a bit, please be nice I’m new to this.
So my JSON file is as follows
{
"Id": "0FFEE-035AB-2050",
"UserName": "[email protected]",
"DefaultPrinter": 1,
"SUPPORT": 1,
"TotalPrinters": 3,
"Printers": [
{
"DeviceName":"\\printers\Canon TM-305",
"DeviceDriverName": "Canon TM-305",
"RotationDirection": 0,
"PrintQuality": 600,
"HpglPrinter": 0,
"ResolutionX": 600,
"ResolutionY": 600,
"DefaultSheet": 1,
"DefaultOrient": 1,
"TotalSize": 49,
"Sheets": [
{
"SheetName": "A0",
"SheetIndex": 4401,
"TotalWidth": 19866,
"TotalHeight": 28086,
"PrintableWidth": 19726,
"PrintableHeight": 27946,
"MarginX": 70,
"MarginY": 70
},
{
"SheetName": "A1",
"SheetIndex": 4403,
"TotalWidth": 14031,
"TotalHeight": 19866,
"PrintableWidth": 13891,
"PrintableHeight": 19726,
"MarginX": 70,
"MarginY": 70
},
{
"SheetName": "ISO B4",
"SheetIndex": 42,
"TotalWidth": 5905,
"TotalHeight": 8338,
"PrintableWidth": 5765,
"PrintableHeight": 8198,
"MarginX": 70,
"MarginY": 70
},
{
"SheetName": "B1",
"SheetIndex": 4410,
"TotalWidth": 17196,
"TotalHeight": 24330,
"PrintableWidth": 17056,
"PrintableHeight": 24190,
"MarginX": 70,
"MarginY": 70
},
{
"SheetName": "B4",
"SheetIndex": 12,
"TotalWidth": 6070,
"TotalHeight": 8598,
"PrintableWidth": 5930,
"PrintableHeight": 8458,
"MarginX": 70,
"MarginY": 70
},
{
"SheetName": "Legal (8.5"x14")",
"SheetIndex": 5,
"TotalWidth": 5100,
"TotalHeight": 8400,
"PrintableWidth": 4960,
"PrintableHeight": 8260,
"MarginX": 70,
"MarginY": 70
},
{
"SheetName": "36"x48" (ARCH E)",
"SheetIndex": 4434,
"TotalWidth": 21600,
"TotalHeight": 28800,
"PrintableWidth": 21460,
"PrintableHeight": 28660,
"MarginX": 70,
"MarginY": 70
}
],
"Bins": [
{
"BinName": "Roll Paper",
"BinIndex": 400
},
{
"BinName": "Cut Sheet",
"BinIndex": 4
}
]
},
{
"DeviceName": "\\printers\HPT7100 (HP Designjet T7100ps)",
"DeviceDriverName": "HP DesignJet T7100 V4",
"RotationDirection": 0,
"PrintQuality": 600,
"HpglPrinter": 0,
"ResolutionX": 600,
"ResolutionY": 600,
"DefaultSheet": 1,
"DefaultOrient": 1,
"TotalSize": 45,
"Sheets": [
{
"SheetName": "Roll 8",
"SheetIndex": 492,
"TotalWidth": 5100,
"TotalHeight": 6600,
"PrintableWidth": 4864,
"PrintableHeight": 0,
"MarginX": 118,
"MarginY": 118
},
{
"SheetName": "Letter",
"SheetIndex": 1,
"TotalWidth": 5100,
"TotalHeight": 6600,
"PrintableWidth": 4864,
"PrintableHeight": 6364,
"MarginX": 118,
"MarginY": 118
},
{
"SheetName": "Tabloid - Sheet",
"SheetIndex": 256,
"TotalWidth": 6600,
"TotalHeight": 10200,
"PrintableWidth": 6364,
"PrintableHeight": 9964,
"MarginX": 118,
"MarginY": 118
}
],
"Bins": [
{
"BinName": "Automatically Select",
"BinIndex": 15
},
{
"BinName": "Roll 1",
"BinIndex": 259
},
{
"BinName": "Roll 2",
"BinIndex": 258
},
{
"BinName": "Roll 3",
"BinIndex": 257
}
]
},
{
"DeviceName": "\\printers\HP PageWide SDI Lobby",
"DeviceDriverName": "HP Universal Printing PCL 6",
"RotationDirection": 0,
"PrintQuality": 600,
"HpglPrinter": 0,
"ResolutionX": 600,
"ResolutionY": 600,
"DefaultSheet": 1,
"DefaultOrient": 1,
"TotalSize": 39,
"Sheets": [
{
"SheetName": "Letter",
"SheetIndex": 1,
"TotalWidth": 5100,
"TotalHeight": 6600,
"PrintableWidth": 4900,
"PrintableHeight": 6400,
"MarginX": 100,
"MarginY": 100
},
{
"SheetName": "Legal",
"SheetIndex": 5,
"TotalWidth": 5100,
"TotalHeight": 8400,
"PrintableWidth": 4900,
"PrintableHeight": 8200,
"MarginX": 100,
"MarginY": 100
},
{
"SheetName": "Statement",
"SheetIndex": 6,
"TotalWidth": 3300,
"TotalHeight": 5100,
"PrintableWidth": 3100,
"PrintableHeight": 4900,
"MarginX": 100,
"MarginY": 100
},
{
"SheetName": "Executive",
"SheetIndex": 7,
"TotalWidth": 4348,
"TotalHeight": 6300,
"PrintableWidth": 4150,
"PrintableHeight": 6100,
"MarginX": 100,
"MarginY": 100
},
{
"SheetName": "A3",
"SheetIndex": 8,
"TotalWidth": 7015,
"TotalHeight": 9921,
"PrintableWidth": 6815,
"PrintableHeight": 9721,
"MarginX": 100,
"MarginY": 100
}
],
"Bins": [
{
"BinName": " Automatically Select",
"BinIndex": 15
},
{
"BinName": " Printer auto select",
"BinIndex": 257
},
{
"BinName": " Manual Feed",
"BinIndex": 258
},
{
"BinName": " Tray 1",
"BinIndex": 259
},
{
"BinName": " Tray 2",
"BinIndex": 260
},
{
"BinName": " Tray 3",
"BinIndex": 261
},
{
"BinName": " Tray 4",
"BinIndex": 262
}
]
}
]
}
My JS function is as follows:
function fetchJson(){
fetch('./temp/printers.json')
.then(response => response.json())
.then(json => console.log(json))
.catch(err => console.log(err))
}
The console logs the JSON object fine but I can’t seem to call it anywhere else? is there a .this chain of some sort I need to do to call the objects within the JSON file? Such as DefualtPrinter
Any help is much appreciated!