Question:
I’ve been working with PowerShell to retrieves the results of an API call to Brightpearl as a JSON string:
I want to retrieve just the section called results….
1 2 |
"results":[[1,1,207,4,3,"2014-09-18T14:15:50.000-04:00",4,"#1014",2],[2,1,207,1,3,"2014-09-29T13:20:52.000-04:00",4,"#1015",2],[3,1,207,1,3,"2014-09-29T13:25:39.000-04:00",4,"#1016",2]]} |
Using ConvertFrom-Json($BpResults.Content), I get only the outer JSON….
1 2 3 4 5 6 |
PS C:> convertfrom-json $BPOrders.Content response reference -------- --------- @{metaData=; results=System.Object[]} @{orderTypeNames=; orderPaymentStatusNames=; orderStatusNames... |
I think maybe some of the rest would be obtainable by digging into the System.Object[]…but can’t figure out the syntax to access that. Ideally, I want to take the results to write out to .CSV file.
Any ideas?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
"Original": { "response": { "metaData": { "resultsAvailable": 3, "resultsReturned": 3, "firstResult": 1, "lastResult": 3, "columns": [ { "name": "orderId", "sortable": true, "filterable": true, "reportDataType": "IDSET", "required": false }, { "name": "orderTypeId", "sortable": true, "filterable": true, "reportDataType": "INTEGER", "referenceData": [ "orderTypeNames" ], "required": false }, { "name": "contactId", "sortable": true, "filterable": true, "reportDataType": "INTEGER", "required": false }, { "name": "orderStatusId", "sortable": true, "filterable": true, "reportDataType": "INTEGER", "referenceData": [ "orderStatusNames" ], "required": false }, { "name": "orderStockStatusId", "sortable": true, "filterable": true, "reportDataType": "INTEGER", "referenceData": [ "orderStockStatusNames" ], "required": false }, { "name": "createdOn", "sortable": true, "filterable": true, "reportDataType": "PERIOD", "required": false }, { "name": "createdById", "sortable": true, "filterable": true, "reportDataType": "INTEGER", "required": false }, { "name": "customerRef", "sortable": true, "filterable": true, "reportDataType": "STRING", "required": false }, { "name": "orderPaymentStatusId", "sortable": true, "filterable": true, "reportDataType": "INTEGER", "referenceData": [ "orderPaymentStatusNames" ], "required": false } ], "sorting": [ { "filterable": { "name": "orderId", "sortable": true, "filterable": true, "reportDataType": "IDSET", "required": false }, "direction": "ASC" } ] }, "results": [ [ 1, 1, 207, 4, 3, "2014-09-18T14: 15: 50.000-04: 00", 4, "#1014", 2 ], [ 2, 1, 207, 1, 3, "2014-09-29T13: 20: 52.000-04: 00", 4, "#1015", 2 ], [ 3, 1, 207, 1, 3, "2014-09-29T13: 25: 39.000-04: 00", 4, "#1016", 2 ] ] }, "reference": { "orderTypeNames": { "1": "SALES_ORDER" }, "orderPaymentStatusNames": { "2": "PARTIALLY_PAID" }, "orderStatusNames": { "1": "Draft/Quote", "4": "Invoiced" }, "orderStockStatusNames": { "3": "Allfulfilled" } } } |
Answer:
1 2 |
ConvertFrom-Json $JSONObject |
then you can address them like:
1 2 |
$JSONObject.response.results |