title: Parsing non-consistent json string in vba
body: <p>I am using Excel VBA together with the excellent <a href="https://github.com/VBA-tools/VBA-JSON" rel="nofollow noreferrer">https://github.com/VBA-tools/VBA-JSON</a> parser which converts a json string to a Dictionary to parse API responses from UPS.</p>
  <p>I am getting error messages when parsing the json responses because the responses I get are non-consistent.</p>
  <p>For example, a response may look like this:</p>
  <pre><code>{&quot;Fault&quot;:{&quot;faultcode&quot;:&quot;Client&quot;, &quot;faultstring&quot;:&quot;An exception has been raised as a result of client data.&quot;, &quot;detail&quot;:{&quot;Errors&quot;:{&quot;ErrorDetail&quot;:{&quot;Severity&quot;:&quot;Hard&quot;, &quot;PrimaryErrorCode&quot;:{&quot;Code&quot;:&quot;9150002&quot;, &quot;Description&quot;:&quot;Invalid or missing inquiry number - TrackingNumber, ShipmentIdentificationNumber, or ReferenceNumber&quot;}}}}}}
  </code></pre>
  <p>But it can also be:</p>
  <pre><code>{&quot;TrackResponse&quot;:{&quot;Response&quot;:{&quot;ResponseStatus&quot;:{&quot;Code&quot;:&quot;1&quot;, &quot;Description&quot;:&quot;Success&quot;}, &quot;TransactionReference&quot;:&quot;&quot;}, &quot;Shipment&quot;:{&quot;InquiryNumber&quot;:{&quot;Code&quot;:&quot;01&quot;, &quot;Description&quot;:&quot;ShipmentIdentificationNumber&quot;, &quot;Value&quot;:&quot;1Z1291249124949&quot;}, &quot;ShipperNumber&quot;:&quot;55443322&quot;, &quot;ShipmentAddress&quot;:[{&quot;Type&quot;:{&quot;Code&quot;:&quot;01&quot;, &quot;Description&quot;:&quot;Shipper Address&quot;}, &quot;Address&quot;:{&quot;AddressLine&quot;:&quot;16 test&quot;, &quot;City&quot;:&quot;test city&quot;, &quot;PostalCode&quot;:&quot;23445&quot;, &quot;CountryCode&quot;:&quot;US&quot;}}, {&quot;Type&quot;:{&quot;Code&quot;:&quot;02&quot;, &quot;Description&quot;:&quot;ShipTo Address&quot;}, &quot;Address&quot;:{&quot;City&quot;:&quot;TEST CITY&quot;, &quot;PostalCode&quot;:&quot;12345&quot;, &quot;CountryCode&quot;:&quot;US&quot;}}], &quot;ShipmentWeight&quot;:{&quot;UnitOfMeasurement&quot;:{&quot;Code&quot;:&quot;KGS&quot;}, &quot;Weight&quot;:&quot;38.00&quot;}, &quot;Service&quot;:{&quot;Code&quot;:&quot;011&quot;, &quot;Description&quot;:&quot;UPS Standard&quot;}, &quot;ReferenceNumber&quot;:[{&quot;Code&quot;:&quot;13&quot;, &quot;Value&quot;:&quot;923484MBS&quot;}, {&quot;Code&quot;:&quot;16&quot;, &quot;Value&quot;:&quot;42111&quot;}], &quot;PickupDate&quot;:&quot;20210118&quot;, &quot;DeliveryDetail&quot;:{&quot;Type&quot;:{&quot;Code&quot;:&quot;03&quot;, &quot;Description&quot;:&quot;Scheduled Delivery&quot;}, &quot;Date&quot;:&quot;20210120&quot;, &quot;Time&quot;:&quot;235900&quot;}, &quot;Package&quot;:[{&quot;TrackingNumber&quot;:&quot;1Z609R234234234234&quot;, &quot;Activity&quot;:{&quot;ActivityLocation&quot;:{&quot;Address&quot;:{&quot;CountryCode&quot;:&quot;US&quot;}}, &quot;Status&quot;:{&quot;Type&quot;:&quot;M&quot;, &quot;Description&quot;:&quot;Shipper created a label, UPS has not received the package yet.&quot;, &quot;Code&quot;:&quot;MP&quot;}, &quot;Date&quot;:&quot;20210118&quot;, &quot;Time&quot;:&quot;104442&quot;}, &quot;PackageWeight&quot;:{&quot;UnitOfMeasurement&quot;:{&quot;Code&quot;:&quot;KGS&quot;}, &quot;Weight&quot;:&quot;19.00&quot;}, &quot;ReferenceNumber&quot;:{&quot;Code&quot;:&quot;19&quot;, &quot;Value&quot;:&quot;42111&quot;}}, {&quot;TrackingNumber&quot;:&quot;1Z23535235235&quot;, &quot;Activity&quot;:{&quot;ActivityLocation&quot;:{&quot;Address&quot;:{&quot;CountryCode&quot;:&quot;US&quot;}}, &quot;Status&quot;:{&quot;Type&quot;:&quot;M&quot;, &quot;Description&quot;:&quot;Shipper created a label, UPS has not received the package yet.&quot;, &quot;Code&quot;:&quot;MP&quot;}, &quot;Date&quot;:&quot;20210118&quot;, &quot;Time&quot;:&quot;104442&quot;}, &quot;PackageWeight&quot;:{&quot;UnitOfMeasurement&quot;:{&quot;Code&quot;:&quot;KGS&quot;}, &quot;Weight&quot;:&quot;19.00&quot;}, &quot;ReferenceNumber&quot;:{&quot;Code&quot;:&quot;19&quot;, &quot;Value&quot;:&quot;42111&quot;}}]}}}
  </code></pre>
  <p>So when I try to do:</p>
  <pre><code>If json(&quot;TrackResponse&quot;)(&quot;Response&quot;)(&quot;ResponseStatus&quot;)(&quot;Description&quot;) = &quot;Success&quot; Then
  Debug.Print &quot;The response is Success&quot;
  End if
  </code></pre>
  <p>and the response was like the first example I get the following error message:</p>
  <pre><code>Run-time error 13:
  Type mismatch
  </code></pre>
  <p>I do not know how to solve this, as I off course cannot predict what the response will be beforehand.</p>
  <p>Any help would be greatly appreciated.</p>