locked
Getting data from JSON string RRS feed

  • Question

  • User-1458727574 posted

    It isn't important for the question but for background I'm pulling data from Sage 300 system via its web API. When I request data regarding an invoice batch which contains 2 invoices and 2 invoice lines on each invoice I get a huge block of JSON data back. 1500 lines in this example. Normally when requesting JSON data from any system I'd have a class which can contain the data, create an object and get that JSON data into that object. However, because of the way the calls work with this system, I have to create a dynamic object type and catch the data that way. This presents a problem as there is no easy way that I can find to get that JSON data into a real object without going through each item in the JSON data and writing it to its own property in the new object. That is tedious for 1500 lines. If I have 10 invoices in a batch with many lines, you could be talking 20,000 or more lines in the JSON.

    So I'm stuck with this line of code that gets the data:

    dynamic newBatch = await SendRequest(new HttpMethod(sHTTPVerb), sFullURI, arInvoiceBatch);

    This means the newBatch is only bound at runtime and because I know the structure is correct and what properties are there, this isn't a big problem. However, getting data out of that invoice batch becomes tricky when I need to get individual bits of info from the invoices within the batch. So you can see the data, here is the JSON data I have to work with in newBatch:

    {
      "@odata.context": "http://localhost/Sage300WebApi/v1.0/-/DEVDAT/AR/$metadata#ARInvoiceBatches/$entity",
      "BatchNumber": 166,
      "BatchDate": "2018-09-05T00:00:00Z",
      "Description": "Freight AR Invoice",
      "NumberOfEntries": 2,
      "BatchTotal": 6660,
      "BatchType": "Entered",
      "BatchStatus": "Open",
      "DefaultInvoiceType": "Summary",
      "LastEntryNumber": 2,
      "PostingSequenceNumber": 0,
      "NumberOfErrors": 0,
      "DateLastEdited": "2018-09-05T00:00:00Z",
      "BatchPrintedFlag": "No",
      "SourceApplication": "AR",
      "ProcessCommand": "UnlockBatchResource",
      "Invoices": [
        {
          "BatchNumber": 166,
          "EntryNumber": 1,
          "CustomerNumber": "TESTREC2C",
          "DocumentNumber": "INVLAX0104A",
          "ShipToLocationCode": "",
          "SpecialInstructions": "",
          "DocumentType": "Invoice",
          "TransactionType": "InvoiceSummaryEntered",
          "OrderNumber": "",
          "PONumber": "",
          "InvoiceDescription": "INVLAX0104A",
          "InvoicePrinted": "No",
          "ApplytoDocument": "",
          "AccountSet": "TRDCAD",
          "DocumentDate": "2017-03-17T00:00:00Z",
          "AsOfDate": "2018-09-05T00:00:00Z",
          "FiscalYear": "2017",
          "FiscalPeriod": "03",
          "CurrencyCode": "CAD",
          "RateType": "SP",
          "RateOverridden": "No",
          "ExchangeRate": 0.75,
          "ApplytoExchangeRate": 0,
          "Terms": "30",
          "TermsCodeOverridden": "No",
          "DueDate": "2017-04-16T00:00:00Z",
          "DiscountDate": null,
          "DiscountPercentage": 0,
          "DiscountAmountAvailable": 0,
          "NumberOfDetails": 2,
          "Salesperson1": "RB",
          "Salesperson2": "",
          "Salesperson3": "",
          "Salesperson4": "",
          "Salesperson5": "",
          "SalesSplitPercentage1": 100,
          "SalesSplitPercentage2": 0,
          "SalesSplitPercentage3": 0,
          "SalesSplitPercentage4": 0,
          "SalesSplitPercentage5": 0,
          "Taxable": "Yes",
          "DoNotCalculationTax": "No",
          "TaxGroup": "USA",
          "TaxAuthority1": "USSTATE",
          "TaxAuthority2": "USCITY",
          "TaxAuthority3": "",
          "TaxAuthority4": "",
          "TaxAuthority5": "",
          "TaxClass1": 1,
          "TaxClass2": 1,
          "TaxClass3": 0,
          "TaxClass4": 0,
          "TaxClass5": 0,
          "TaxBase1": 3000,
          "TaxBase2": 3000,
          "TaxBase3": 0,
          "TaxBase4": 0,
          "TaxBase5": 0,
          "TaxAmount1": 150,
          "TaxAmount2": 180,
          "TaxAmount3": 0,
          "TaxAmount4": 0,
          "TaxAmount5": 0,
          "TaxableAmount": 3000,
          "NonTaxableAmount": 0,
          "TaxTotal": 330,
          "DocumentTotalBeforeTax": 3000,
          "PrepaymentAmount": 0,
          "NumberOfScheduledPayments": 1,
          "TotalPaymentAmountScheduled": 3330,
          "DocumentTotalIncludingTax": 3330,
          "RecurringChargeCode": "",
          "DateGenerated": null,
          "PrepaymentNumber": "",
          "RecurringBillingCycle": "",
          "ShipToLocationName": "",
          "ShipToAddressLine1": "",
          "ShipToAddressLine2": "",
          "ShipToAddressLine3": "",
          "ShipToAddressLine4": "",
          "ShipToCity": "",
          "ShipToStateProvince": "",
          "ShipToZipPostalCode": "",
          "ShipToCountry": "",
          "ShipToContactName": "",
          "ShipToPhoneNumber": "",
          "ShipToFaxNumber": "",
          "RateDate": "2017-03-17T00:00:00Z",
          "CustNatlOverCreditFlag": "Neitherovercreditlimit",
          "AmountDue": 3330,
          "RateOperator": "Multiply",
          "DrillDownApplicationSource": "",
          "DrillDownType": 0,
          "DrillDownLinkNumber": 0,
          "ForceRereadOfIBSTotals": 0,
          "ProcessCommand": "CalculateTaxes",
          "ShipViaCode": "",
          "ShipViaDescription": "",
          "PropertyCode": "ModeNormal1Batch2",
          "PropertyValue": 1,
          "JobRelated": "No",
          "ErrorBatch": 0,
          "ErrorEntry": 0,
          "ShipToEmail": "",
          "ShipToContactsPhone": "",
          "ShipToContactsFax": "",
          "ShipToContactsEmail": "",
          "DiscountBaseWithTax": 0,
          "DiscountBaseWithoutTax": 0,
          "DiscountBase": 0,
          "InvoiceType": "Summary",
          "RetainageInvoice": "No",
          "OriginalDocumentNumber": "",
          "HasRetainage": "No",
          "RetainageAmount": 0,
          "PercentRetained": 0,
          "DaysRetained": 0,
          "RetainageDueDate": null,
          "RetainageTermsCode": "",
          "RetainageDueDateOverride": "No",
          "RetainageAmountOverride": "No",
          "RetainageExchangeRate": "UseOriginalDocumentExchangeRate",
          "NumberOfOptionalFields": 4,
          "SourceApplication": "AR",
          "ARVersionCreatedIn": "65A",
          "TaxStateVersion": 2,
          "ReportRetainageTax": 0,
          "TaxReportingCurrencyCode": "USD",
          "TaxReportingCalculateMethod": "Yes",
          "TaxReportingExchangeRate": 1,
          "TaxReportingRateType": "SP",
          "TaxReportingRateDate": "2017-03-17T00:00:00Z",
          "TaxReportingRateOperator": "Multiply",
          "TaxReportingRateOverride": "No",
          "TaxReportingAmount1": 150,
          "TaxReportingAmount2": 180,
          "TaxReportingAmount3": 0,
          "TaxReportingAmount4": 0,
          "TaxReportingAmount5": 0,
          "TaxReportingTotal": 330,
          "RetainageTaxBase1": 0,
          "RetainageTaxBase2": 0,
          "RetainageTaxBase3": 0,
          "RetainageTaxBase4": 0,
          "RetainageTaxBase5": 0,
          "RetainageTaxAmount1": 0,
          "RetainageTaxAmount2": 0,
          "RetainageTaxAmount3": 0,
          "RetainageTaxAmount4": 0,
          "RetainageTaxAmount5": 0,
          "FunctionalTaxBase1": 2250,
          "FunctionalTaxBase2": 2250,
          "FunctionalTaxBase3": 0,
          "FunctionalTaxBase4": 0,
          "FunctionalTaxBase5": 0,
          "FunctionalTaxAmount1": 112.5,
          "FunctionalTaxAmount2": 135,
          "FunctionalTaxAmount3": 0,
          "FunctionalTaxAmount4": 0,
          "FunctionalTaxAmount5": 0,
          "FunctionalDistributionWithTaxTotal": 2497.5,
          "FunctionalRetainageAmount": 0,
          "FunctionalDiscountAmount": 0,
          "FunctionalDistributionWithoutTaxTotal": 2250,
          "FunctionalPrepaymentAmount": 0,
          "FunctionalAmountDue": 2497.5,
          "LabelPrinted": "No",
          "RetainageTaxTotal": 0,
          "TaxAmount1Total": 150,
          "TaxAmount2Total": 180,
          "TaxAmount3Total": 0,
          "TaxAmount4Total": 0,
          "TaxAmount5Total": 0,
          "RetainageAmountFromDetails": 0,
          "ShipmentNumber": "",
          "DoOECostingAndConsolidation": "No",
          "EnteredBy": "ADMIN",
          "PostingDate": "2017-03-17T00:00:00Z",
          "ExportDeclarationNumber": "",
          "InvoiceDetails": [
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "LineNumber": 20,
              "ItemNumber": "",
              "DistributionCode": "FRT",
              "Description": "AIR FREIGHT CHARGE",
              "UnitOfMeasure": "",
              "Quantity": 0,
              "Cost": 0,
              "Price": 0,
              "ExtendedAmountWithTIP": 2000,
              "COGSAmount": 0,
              "ExtendedAmountWithoutTIP": 2000,
              "TaxTotal": 220,
              "TaxBase1": 2000,
              "TaxBase2": 2000,
              "TaxBase3": 0,
              "TaxBase4": 0,
              "TaxBase5": 0,
              "TaxClass1": 1,
              "TaxClass2": 1,
              "TaxClass3": 0,
              "TaxClass4": 0,
              "TaxClass5": 0,
              "TaxIncluded1": "No",
              "TaxIncluded2": "No",
              "TaxIncluded3": "No",
              "TaxIncluded4": "No",
              "TaxIncluded5": "No",
              "TaxRate1": 5,
              "TaxRate2": 6,
              "TaxRate3": 0,
              "TaxRate4": 0,
              "TaxRate5": 0,
              "TaxAmount1": 100,
              "TaxAmount2": 120,
              "TaxAmount3": 0,
              "TaxAmount4": 0,
              "TaxAmount5": 0,
              "RevenueAccount": "01-0000-4050",
              "InventoryAccount": "",
              "COGSAccount": "",
              "Comments": "COMMENT",
              "PrintComment": 0,
              "ItemCost": 0,
              "Contract": "",
              "Project": "",
              "Category": "",
              "ProjectCategoryResource": "",
              "TransactionNumber": 0,
              "CostClass": "None",
              "BillingDate": null,
              "CommentAttached": "Yes",
              "Discountable": "No",
              "OriginalLineIdentifier": 0,
              "RetainageAmount": 0,
              "PercentRetained": 0,
              "DaysRetained": 0,
              "RetainageDueDate": null,
              "RetainageDueDateOverride": "No",
              "RetainageAmountOverride": "No",
              "Values": 5,
              "ProcessCommandCode": "InsertOptionalFields",
              "RetainageDistributionAmount": 0,
              "RetainageCOGSAmount": 0,
              "RetainageAlternateBaseAmount": 0,
              "InvoicedRetainageDistribution": 0,
              "InvoicedRetainageCOGS": 0,
              "InvoicedRetainageAlternateBas": 0,
              "TaxReportingAmount1": 100,
              "TaxReportingAmount2": 120,
              "TaxReportingAmount3": 0,
              "TaxReportingAmount4": 0,
              "TaxReportingAmount5": 0,
              "TaxReportingTotal": 220,
              "RetainageTaxBase1": 0,
              "RetainageTaxBase2": 0,
              "RetainageTaxBase3": 0,
              "RetainageTaxBase4": 0,
              "RetainageTaxBase5": 0,
              "RetainageTaxAmount1": 0,
              "RetainageTaxAmount2": 0,
              "RetainageTaxAmount3": 0,
              "RetainageTaxAmount4": 0,
              "RetainageTaxAmount5": 0,
              "FunctionalTaxBase1": 1500,
              "FunctionalTaxBase2": 1500,
              "FunctionalTaxBase3": 0,
              "FunctionalTaxBase4": 0,
              "FunctionalTaxBase5": 0,
              "FunctionalTaxAmount1": 75,
              "FunctionalTaxAmount2": 90,
              "FunctionalTaxAmount3": 0,
              "FunctionalTaxAmount4": 0,
              "FunctionalTaxAmount5": 0,
              "FunctionalRetainageTaxAmount1": 0,
              "FunctionalRetainageTaxAmount2": 0,
              "FunctionalRetainageTaxAmount3": 0,
              "FunctionalRetainageTaxAmount4": 0,
              "FunctionalRetainageTaxAmount5": 0,
              "FunctionalDistributionNetOfTaxes": 1500,
              "FunctionalRetainageAmount": 0,
              "FunctionalCOGSAmount": 0,
              "FunctionalCost": 0,
              "FunctionalPrice": 0,
              "FunctionalExtendedAmountWithTIP": 1500,
              "RetainageTaxTotal": 0,
              "TaxAmount1Total": 100,
              "TaxAmount2Total": 120,
              "TaxAmount3Total": 0,
              "TaxAmount4Total": 0,
              "TaxAmount5Total": 0,
              "CurrencyRetainageAmount": 0,
              "CurrencyRetainageDistributionAmount": 0,
              "CurrencyCOGSAmount": 0,
              "CurrencyAlternateBaseAmount": 0,
              "InvoiceDetailOptionalFields": [
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 20,
                  "OptionalField": "CHRGWT",
                  "Value": "200.5",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "200.5",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Charge Weight",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 20,
                  "OptionalField": "CHRGWTUOM",
                  "Value": "KGS",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "KGS",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Charge Weight Unit of Measure",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 20,
                  "OptionalField": "JOBDATE",
                  "Value": "2017-03-16",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "2017-03-16",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Date",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 20,
                  "OptionalField": "JOBNO",
                  "Value": "JHAELAX0005-1",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "JHAELAX0005-1",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 20,
                  "OptionalField": "SHPNO",
                  "Value": "HAELAX0005-1",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "HAELAX0005-1",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Shipment Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                }
              ],
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "LineNumber": 40,
              "ItemNumber": "",
              "DistributionCode": "FRT",
              "Description": "AIR FREIGHT CHARGE",
              "UnitOfMeasure": "",
              "Quantity": 0,
              "Cost": 0,
              "Price": 0,
              "ExtendedAmountWithTIP": 1000,
              "COGSAmount": 0,
              "ExtendedAmountWithoutTIP": 1000,
              "TaxTotal": 110,
              "TaxBase1": 1000,
              "TaxBase2": 1000,
              "TaxBase3": 0,
              "TaxBase4": 0,
              "TaxBase5": 0,
              "TaxClass1": 1,
              "TaxClass2": 1,
              "TaxClass3": 0,
              "TaxClass4": 0,
              "TaxClass5": 0,
              "TaxIncluded1": "No",
              "TaxIncluded2": "No",
              "TaxIncluded3": "No",
              "TaxIncluded4": "No",
              "TaxIncluded5": "No",
              "TaxRate1": 5,
              "TaxRate2": 6,
              "TaxRate3": 0,
              "TaxRate4": 0,
              "TaxRate5": 0,
              "TaxAmount1": 50,
              "TaxAmount2": 60,
              "TaxAmount3": 0,
              "TaxAmount4": 0,
              "TaxAmount5": 0,
              "RevenueAccount": "01-0000-4050",
              "InventoryAccount": "",
              "COGSAccount": "",
              "Comments": "COMMENT",
              "PrintComment": 0,
              "ItemCost": 0,
              "Contract": "",
              "Project": "",
              "Category": "",
              "ProjectCategoryResource": "",
              "TransactionNumber": 0,
              "CostClass": "None",
              "BillingDate": null,
              "CommentAttached": "Yes",
              "Discountable": "No",
              "OriginalLineIdentifier": 0,
              "RetainageAmount": 0,
              "PercentRetained": 0,
              "DaysRetained": 0,
              "RetainageDueDate": null,
              "RetainageDueDateOverride": "No",
              "RetainageAmountOverride": "No",
              "Values": 3,
              "ProcessCommandCode": "InsertOptionalFields",
              "RetainageDistributionAmount": 0,
              "RetainageCOGSAmount": 0,
              "RetainageAlternateBaseAmount": 0,
              "InvoicedRetainageDistribution": 0,
              "InvoicedRetainageCOGS": 0,
              "InvoicedRetainageAlternateBas": 0,
              "TaxReportingAmount1": 50,
              "TaxReportingAmount2": 60,
              "TaxReportingAmount3": 0,
              "TaxReportingAmount4": 0,
              "TaxReportingAmount5": 0,
              "TaxReportingTotal": 110,
              "RetainageTaxBase1": 0,
              "RetainageTaxBase2": 0,
              "RetainageTaxBase3": 0,
              "RetainageTaxBase4": 0,
              "RetainageTaxBase5": 0,
              "RetainageTaxAmount1": 0,
              "RetainageTaxAmount2": 0,
              "RetainageTaxAmount3": 0,
              "RetainageTaxAmount4": 0,
              "RetainageTaxAmount5": 0,
              "FunctionalTaxBase1": 750,
              "FunctionalTaxBase2": 750,
              "FunctionalTaxBase3": 0,
              "FunctionalTaxBase4": 0,
              "FunctionalTaxBase5": 0,
              "FunctionalTaxAmount1": 37.5,
              "FunctionalTaxAmount2": 45,
              "FunctionalTaxAmount3": 0,
              "FunctionalTaxAmount4": 0,
              "FunctionalTaxAmount5": 0,
              "FunctionalRetainageTaxAmount1": 0,
              "FunctionalRetainageTaxAmount2": 0,
              "FunctionalRetainageTaxAmount3": 0,
              "FunctionalRetainageTaxAmount4": 0,
              "FunctionalRetainageTaxAmount5": 0,
              "FunctionalDistributionNetOfTaxes": 750,
              "FunctionalRetainageAmount": 0,
              "FunctionalCOGSAmount": 0,
              "FunctionalCost": 0,
              "FunctionalPrice": 0,
              "FunctionalExtendedAmountWithTIP": 750,
              "RetainageTaxTotal": 0,
              "TaxAmount1Total": 50,
              "TaxAmount2Total": 60,
              "TaxAmount3Total": 0,
              "TaxAmount4Total": 0,
              "TaxAmount5Total": 0,
              "CurrencyRetainageAmount": 0,
              "CurrencyRetainageDistributionAmount": 0,
              "CurrencyCOGSAmount": 0,
              "CurrencyAlternateBaseAmount": 0,
              "InvoiceDetailOptionalFields": [
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 40,
                  "OptionalField": "JOBDATE",
                  "Value": "2017-03-16",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "2017-03-16",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Date",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 40,
                  "OptionalField": "JOBNO",
                  "Value": "JHAELAX0005-2",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "JHAELAX0005-2",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 1,
                  "LineNumber": 40,
                  "OptionalField": "SHPNO",
                  "Value": "HAELAX0005-2",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "HAELAX0005-2",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Shipment Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                }
              ],
              "UpdateOperation": "Unspecified"
            }
          ],
          "InvoicePaymentSchedules": [
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "PaymentNumber": 1,
              "DueDate": "2017-04-16T00:00:00Z",
              "AmountDue": 3330,
              "DiscountDate": null,
              "DiscountAmount": 0,
              "FunctionalAmountDue": 2497.5,
              "FunctionalDiscountAmount": 0,
              "UpdateOperation": "Unspecified"
            }
          ],
          "InvoiceOptionalFields": [
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "OptionalField": "BIZTYPE",
              "Value": "AE",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "AE",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "Biz Type",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "OptionalField": "OWNERID",
              "Value": "LAX",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "LAX",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "Owner ID",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "OptionalField": "PARTYID",
              "Value": "TESTREC",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "TESTREC",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "Party Id",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 1,
              "OptionalField": "UNID",
              "Value": "10005",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "10005",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "UN ID",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            }
          ],
          "UpdateOperation": "Unspecified"
        },
        {
          "BatchNumber": 166,
          "EntryNumber": 2,
          "CustomerNumber": "TESTREC3",
          "DocumentNumber": "INVLAX0105A",
          "ShipToLocationCode": "",
          "SpecialInstructions": "",
          "DocumentType": "Invoice",
          "TransactionType": "InvoiceSummaryEntered",
          "OrderNumber": "",
          "PONumber": "",
          "InvoiceDescription": "INVLAX0105A",
          "InvoicePrinted": "No",
          "ApplytoDocument": "",
          "AccountSet": "TRDCAD",
          "DocumentDate": "2017-03-17T00:00:00Z",
          "AsOfDate": "2018-09-05T00:00:00Z",
          "FiscalYear": "2017",
          "FiscalPeriod": "03",
          "CurrencyCode": "CAD",
          "RateType": "SP",
          "RateOverridden": "No",
          "ExchangeRate": 0.75,
          "ApplytoExchangeRate": 0,
          "Terms": "30",
          "TermsCodeOverridden": "No",
          "DueDate": "2017-04-16T00:00:00Z",
          "DiscountDate": null,
          "DiscountPercentage": 0,
          "DiscountAmountAvailable": 0,
          "NumberOfDetails": 2,
          "Salesperson1": "RB",
          "Salesperson2": "",
          "Salesperson3": "",
          "Salesperson4": "",
          "Salesperson5": "",
          "SalesSplitPercentage1": 100,
          "SalesSplitPercentage2": 0,
          "SalesSplitPercentage3": 0,
          "SalesSplitPercentage4": 0,
          "SalesSplitPercentage5": 0,
          "Taxable": "Yes",
          "DoNotCalculationTax": "No",
          "TaxGroup": "USA",
          "TaxAuthority1": "USSTATE",
          "TaxAuthority2": "USCITY",
          "TaxAuthority3": "",
          "TaxAuthority4": "",
          "TaxAuthority5": "",
          "TaxClass1": 1,
          "TaxClass2": 1,
          "TaxClass3": 0,
          "TaxClass4": 0,
          "TaxClass5": 0,
          "TaxBase1": 3000,
          "TaxBase2": 3000,
          "TaxBase3": 0,
          "TaxBase4": 0,
          "TaxBase5": 0,
          "TaxAmount1": 150,
          "TaxAmount2": 180,
          "TaxAmount3": 0,
          "TaxAmount4": 0,
          "TaxAmount5": 0,
          "TaxableAmount": 3000,
          "NonTaxableAmount": 0,
          "TaxTotal": 330,
          "DocumentTotalBeforeTax": 3000,
          "PrepaymentAmount": 0,
          "NumberOfScheduledPayments": 1,
          "TotalPaymentAmountScheduled": 3330,
          "DocumentTotalIncludingTax": 3330,
          "RecurringChargeCode": "",
          "DateGenerated": null,
          "PrepaymentNumber": "",
          "RecurringBillingCycle": "",
          "ShipToLocationName": "",
          "ShipToAddressLine1": "TESTREC ADDR 1",
          "ShipToAddressLine2": "TESTREC ADDR 2",
          "ShipToAddressLine3": "TESTREC ADDR 3",
          "ShipToAddressLine4": "TESTREC ADDR 4",
          "ShipToCity": "LAX",
          "ShipToStateProvince": "CA",
          "ShipToZipPostalCode": "90003",
          "ShipToCountry": "US",
          "ShipToContactName": "CONTACT PERSON",
          "ShipToPhoneNumber": "91962312",
          "ShipToFaxNumber": "91962313",
          "RateDate": "2017-03-17T00:00:00Z",
          "CustNatlOverCreditFlag": "Neitherovercreditlimit",
          "AmountDue": 3330,
          "RateOperator": "Multiply",
          "DrillDownApplicationSource": "",
          "DrillDownType": 0,
          "DrillDownLinkNumber": 0,
          "ForceRereadOfIBSTotals": 0,
          "ProcessCommand": "CalculateTaxes",
          "ShipViaCode": "",
          "ShipViaDescription": "",
          "PropertyCode": "ModeNormal1Batch2",
          "PropertyValue": 1,
          "JobRelated": "No",
          "ErrorBatch": 0,
          "ErrorEntry": 0,
          "ShipToEmail": "email2@abc.com",
          "ShipToContactsPhone": "",
          "ShipToContactsFax": "",
          "ShipToContactsEmail": "email1@abc.com",
          "DiscountBaseWithTax": 0,
          "DiscountBaseWithoutTax": 0,
          "DiscountBase": 0,
          "InvoiceType": "Summary",
          "RetainageInvoice": "No",
          "OriginalDocumentNumber": "",
          "HasRetainage": "No",
          "RetainageAmount": 0,
          "PercentRetained": 0,
          "DaysRetained": 0,
          "RetainageDueDate": null,
          "RetainageTermsCode": "",
          "RetainageDueDateOverride": "No",
          "RetainageAmountOverride": "No",
          "RetainageExchangeRate": "UseOriginalDocumentExchangeRate",
          "NumberOfOptionalFields": 4,
          "SourceApplication": "AR",
          "ARVersionCreatedIn": "65A",
          "TaxStateVersion": 2,
          "ReportRetainageTax": 0,
          "TaxReportingCurrencyCode": "USD",
          "TaxReportingCalculateMethod": "Yes",
          "TaxReportingExchangeRate": 1,
          "TaxReportingRateType": "SP",
          "TaxReportingRateDate": "2017-03-17T00:00:00Z",
          "TaxReportingRateOperator": "Multiply",
          "TaxReportingRateOverride": "No",
          "TaxReportingAmount1": 150,
          "TaxReportingAmount2": 180,
          "TaxReportingAmount3": 0,
          "TaxReportingAmount4": 0,
          "TaxReportingAmount5": 0,
          "TaxReportingTotal": 330,
          "RetainageTaxBase1": 0,
          "RetainageTaxBase2": 0,
          "RetainageTaxBase3": 0,
          "RetainageTaxBase4": 0,
          "RetainageTaxBase5": 0,
          "RetainageTaxAmount1": 0,
          "RetainageTaxAmount2": 0,
          "RetainageTaxAmount3": 0,
          "RetainageTaxAmount4": 0,
          "RetainageTaxAmount5": 0,
          "FunctionalTaxBase1": 2250,
          "FunctionalTaxBase2": 2250,
          "FunctionalTaxBase3": 0,
          "FunctionalTaxBase4": 0,
          "FunctionalTaxBase5": 0,
          "FunctionalTaxAmount1": 112.5,
          "FunctionalTaxAmount2": 135,
          "FunctionalTaxAmount3": 0,
          "FunctionalTaxAmount4": 0,
          "FunctionalTaxAmount5": 0,
          "FunctionalDistributionWithTaxTotal": 2497.5,
          "FunctionalRetainageAmount": 0,
          "FunctionalDiscountAmount": 0,
          "FunctionalDistributionWithoutTaxTotal": 2250,
          "FunctionalPrepaymentAmount": 0,
          "FunctionalAmountDue": 2497.5,
          "LabelPrinted": "No",
          "RetainageTaxTotal": 0,
          "TaxAmount1Total": 150,
          "TaxAmount2Total": 180,
          "TaxAmount3Total": 0,
          "TaxAmount4Total": 0,
          "TaxAmount5Total": 0,
          "RetainageAmountFromDetails": 0,
          "ShipmentNumber": "",
          "DoOECostingAndConsolidation": "No",
          "EnteredBy": "ADMIN",
          "PostingDate": "2017-03-17T00:00:00Z",
          "ExportDeclarationNumber": "",
          "InvoiceDetails": [
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "LineNumber": 20,
              "ItemNumber": "",
              "DistributionCode": "FRT",
              "Description": "AIR FREIGHT CHARGE",
              "UnitOfMeasure": "",
              "Quantity": 0,
              "Cost": 0,
              "Price": 0,
              "ExtendedAmountWithTIP": 2000,
              "COGSAmount": 0,
              "ExtendedAmountWithoutTIP": 2000,
              "TaxTotal": 220,
              "TaxBase1": 2000,
              "TaxBase2": 2000,
              "TaxBase3": 0,
              "TaxBase4": 0,
              "TaxBase5": 0,
              "TaxClass1": 1,
              "TaxClass2": 1,
              "TaxClass3": 0,
              "TaxClass4": 0,
              "TaxClass5": 0,
              "TaxIncluded1": "No",
              "TaxIncluded2": "No",
              "TaxIncluded3": "No",
              "TaxIncluded4": "No",
              "TaxIncluded5": "No",
              "TaxRate1": 5,
              "TaxRate2": 6,
              "TaxRate3": 0,
              "TaxRate4": 0,
              "TaxRate5": 0,
              "TaxAmount1": 100,
              "TaxAmount2": 120,
              "TaxAmount3": 0,
              "TaxAmount4": 0,
              "TaxAmount5": 0,
              "RevenueAccount": "01-0000-4050",
              "InventoryAccount": "",
              "COGSAccount": "",
              "Comments": "COMMENT",
              "PrintComment": 0,
              "ItemCost": 0,
              "Contract": "",
              "Project": "",
              "Category": "",
              "ProjectCategoryResource": "",
              "TransactionNumber": 0,
              "CostClass": "None",
              "BillingDate": null,
              "CommentAttached": "Yes",
              "Discountable": "No",
              "OriginalLineIdentifier": 0,
              "RetainageAmount": 0,
              "PercentRetained": 0,
              "DaysRetained": 0,
              "RetainageDueDate": null,
              "RetainageDueDateOverride": "No",
              "RetainageAmountOverride": "No",
              "Values": 5,
              "ProcessCommandCode": "InsertOptionalFields",
              "RetainageDistributionAmount": 0,
              "RetainageCOGSAmount": 0,
              "RetainageAlternateBaseAmount": 0,
              "InvoicedRetainageDistribution": 0,
              "InvoicedRetainageCOGS": 0,
              "InvoicedRetainageAlternateBas": 0,
              "TaxReportingAmount1": 100,
              "TaxReportingAmount2": 120,
              "TaxReportingAmount3": 0,
              "TaxReportingAmount4": 0,
              "TaxReportingAmount5": 0,
              "TaxReportingTotal": 220,
              "RetainageTaxBase1": 0,
              "RetainageTaxBase2": 0,
              "RetainageTaxBase3": 0,
              "RetainageTaxBase4": 0,
              "RetainageTaxBase5": 0,
              "RetainageTaxAmount1": 0,
              "RetainageTaxAmount2": 0,
              "RetainageTaxAmount3": 0,
              "RetainageTaxAmount4": 0,
              "RetainageTaxAmount5": 0,
              "FunctionalTaxBase1": 1500,
              "FunctionalTaxBase2": 1500,
              "FunctionalTaxBase3": 0,
              "FunctionalTaxBase4": 0,
              "FunctionalTaxBase5": 0,
              "FunctionalTaxAmount1": 75,
              "FunctionalTaxAmount2": 90,
              "FunctionalTaxAmount3": 0,
              "FunctionalTaxAmount4": 0,
              "FunctionalTaxAmount5": 0,
              "FunctionalRetainageTaxAmount1": 0,
              "FunctionalRetainageTaxAmount2": 0,
              "FunctionalRetainageTaxAmount3": 0,
              "FunctionalRetainageTaxAmount4": 0,
              "FunctionalRetainageTaxAmount5": 0,
              "FunctionalDistributionNetOfTaxes": 1500,
              "FunctionalRetainageAmount": 0,
              "FunctionalCOGSAmount": 0,
              "FunctionalCost": 0,
              "FunctionalPrice": 0,
              "FunctionalExtendedAmountWithTIP": 1500,
              "RetainageTaxTotal": 0,
              "TaxAmount1Total": 100,
              "TaxAmount2Total": 120,
              "TaxAmount3Total": 0,
              "TaxAmount4Total": 0,
              "TaxAmount5Total": 0,
              "CurrencyRetainageAmount": 0,
              "CurrencyRetainageDistributionAmount": 0,
              "CurrencyCOGSAmount": 0,
              "CurrencyAlternateBaseAmount": 0,
              "InvoiceDetailOptionalFields": [
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 20,
                  "OptionalField": "CHRGWT",
                  "Value": "200.5",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "200.5",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Charge Weight",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 20,
                  "OptionalField": "CHRGWTUOM",
                  "Value": "KGS",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "KGS",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Charge Weight Unit of Measure",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 20,
                  "OptionalField": "JOBDATE",
                  "Value": "2017-03-16",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "2017-03-16",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Date",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 20,
                  "OptionalField": "JOBNO",
                  "Value": "JHAELAX0005-1",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "JHAELAX0005-1",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 20,
                  "OptionalField": "SHPNO",
                  "Value": "HAELAX0005-1",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "HAELAX0005-1",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Shipment Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                }
              ],
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "LineNumber": 40,
              "ItemNumber": "",
              "DistributionCode": "FRT",
              "Description": "AIR FREIGHT CHARGE",
              "UnitOfMeasure": "",
              "Quantity": 0,
              "Cost": 0,
              "Price": 0,
              "ExtendedAmountWithTIP": 1000,
              "COGSAmount": 0,
              "ExtendedAmountWithoutTIP": 1000,
              "TaxTotal": 110,
              "TaxBase1": 1000,
              "TaxBase2": 1000,
              "TaxBase3": 0,
              "TaxBase4": 0,
              "TaxBase5": 0,
              "TaxClass1": 1,
              "TaxClass2": 1,
              "TaxClass3": 0,
              "TaxClass4": 0,
              "TaxClass5": 0,
              "TaxIncluded1": "No",
              "TaxIncluded2": "No",
              "TaxIncluded3": "No",
              "TaxIncluded4": "No",
              "TaxIncluded5": "No",
              "TaxRate1": 5,
              "TaxRate2": 6,
              "TaxRate3": 0,
              "TaxRate4": 0,
              "TaxRate5": 0,
              "TaxAmount1": 50,
              "TaxAmount2": 60,
              "TaxAmount3": 0,
              "TaxAmount4": 0,
              "TaxAmount5": 0,
              "RevenueAccount": "01-0000-4050",
              "InventoryAccount": "",
              "COGSAccount": "",
              "Comments": "COMMENT",
              "PrintComment": 0,
              "ItemCost": 0,
              "Contract": "",
              "Project": "",
              "Category": "",
              "ProjectCategoryResource": "",
              "TransactionNumber": 0,
              "CostClass": "None",
              "BillingDate": null,
              "CommentAttached": "Yes",
              "Discountable": "No",
              "OriginalLineIdentifier": 0,
              "RetainageAmount": 0,
              "PercentRetained": 0,
              "DaysRetained": 0,
              "RetainageDueDate": null,
              "RetainageDueDateOverride": "No",
              "RetainageAmountOverride": "No",
              "Values": 3,
              "ProcessCommandCode": "InsertOptionalFields",
              "RetainageDistributionAmount": 0,
              "RetainageCOGSAmount": 0,
              "RetainageAlternateBaseAmount": 0,
              "InvoicedRetainageDistribution": 0,
              "InvoicedRetainageCOGS": 0,
              "InvoicedRetainageAlternateBas": 0,
              "TaxReportingAmount1": 50,
              "TaxReportingAmount2": 60,
              "TaxReportingAmount3": 0,
              "TaxReportingAmount4": 0,
              "TaxReportingAmount5": 0,
              "TaxReportingTotal": 110,
              "RetainageTaxBase1": 0,
              "RetainageTaxBase2": 0,
              "RetainageTaxBase3": 0,
              "RetainageTaxBase4": 0,
              "RetainageTaxBase5": 0,
              "RetainageTaxAmount1": 0,
              "RetainageTaxAmount2": 0,
              "RetainageTaxAmount3": 0,
              "RetainageTaxAmount4": 0,
              "RetainageTaxAmount5": 0,
              "FunctionalTaxBase1": 750,
              "FunctionalTaxBase2": 750,
              "FunctionalTaxBase3": 0,
              "FunctionalTaxBase4": 0,
              "FunctionalTaxBase5": 0,
              "FunctionalTaxAmount1": 37.5,
              "FunctionalTaxAmount2": 45,
              "FunctionalTaxAmount3": 0,
              "FunctionalTaxAmount4": 0,
              "FunctionalTaxAmount5": 0,
              "FunctionalRetainageTaxAmount1": 0,
              "FunctionalRetainageTaxAmount2": 0,
              "FunctionalRetainageTaxAmount3": 0,
              "FunctionalRetainageTaxAmount4": 0,
              "FunctionalRetainageTaxAmount5": 0,
              "FunctionalDistributionNetOfTaxes": 750,
              "FunctionalRetainageAmount": 0,
              "FunctionalCOGSAmount": 0,
              "FunctionalCost": 0,
              "FunctionalPrice": 0,
              "FunctionalExtendedAmountWithTIP": 750,
              "RetainageTaxTotal": 0,
              "TaxAmount1Total": 50,
              "TaxAmount2Total": 60,
              "TaxAmount3Total": 0,
              "TaxAmount4Total": 0,
              "TaxAmount5Total": 0,
              "CurrencyRetainageAmount": 0,
              "CurrencyRetainageDistributionAmount": 0,
              "CurrencyCOGSAmount": 0,
              "CurrencyAlternateBaseAmount": 0,
              "InvoiceDetailOptionalFields": [
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 40,
                  "OptionalField": "JOBDATE",
                  "Value": "2017-03-16",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "2017-03-16",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Date",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 40,
                  "OptionalField": "JOBNO",
                  "Value": "JHAELAX0005-2",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "JHAELAX0005-2",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Job Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                },
                {
                  "BatchNumber": 166,
                  "EntryNumber": 2,
                  "LineNumber": 40,
                  "OptionalField": "SHPNO",
                  "Value": "HAELAX0005-2",
                  "InvoiceDetailOptionalFieldType": "Text",
                  "Length": 60,
                  "Decimals": 0,
                  "AllowBlank": false,
                  "Validate": false,
                  "ValueSet": "Yes",
                  "TypedValueFieldIndex": 21,
                  "TextValue": "HAELAX0005-2",
                  "AmountValue": 0,
                  "NumberValue": 0,
                  "IntegerValue": 0,
                  "YesNoValue": false,
                  "DateValue": null,
                  "TimeValue": "1899-12-30T00:00:00Z",
                  "OptionalFieldDescription": "Shipment Number",
                  "ValueDescription": "",
                  "UpdateOperation": "Unspecified"
                }
              ],
              "UpdateOperation": "Unspecified"
            }
          ],
          "InvoicePaymentSchedules": [
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "PaymentNumber": 1,
              "DueDate": "2017-04-16T00:00:00Z",
              "AmountDue": 3330,
              "DiscountDate": null,
              "DiscountAmount": 0,
              "FunctionalAmountDue": 2497.5,
              "FunctionalDiscountAmount": 0,
              "UpdateOperation": "Unspecified"
            }
          ],
          "InvoiceOptionalFields": [
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "OptionalField": "BIZTYPE",
              "Value": "AE",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "AE",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "Biz Type",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "OptionalField": "OWNERID",
              "Value": "LAX",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "LAX",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "Owner ID",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "OptionalField": "PARTYID",
              "Value": "TESTREC",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "TESTREC",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "Party Id",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            },
            {
              "BatchNumber": 166,
              "EntryNumber": 2,
              "OptionalField": "UNID",
              "Value": "10005",
              "InvoiceOptionalFieldType": "Text",
              "Length": 60,
              "Decimals": 0,
              "AllowBlank": false,
              "Validate": false,
              "ValueSet": "Yes",
              "TypedValueFieldIndex": 21,
              "TextValue": "10005",
              "AmountValue": 0,
              "NumberValue": 0,
              "IntegerValue": 0,
              "YesNoValue": false,
              "DateValue": null,
              "TimeValue": "1899-12-30T00:00:00Z",
              "OptionalFieldDescription": "UN ID",
              "ValueDescription": "",
              "UpdateOperation": "Unspecified"
            }
          ],
          "UpdateOperation": "Unspecified"
        }
      ],
      "UpdateOperation": "Unspecified"
    }

    In this example, there are 2 invoices, but there could be anything from 1 to potentially hundreds. Now I need to get some data out from each invoice. So I modified the above line of code and started trying to work it out using NewtonSoft JSON library which is what I am using anyway.

                JObject newBatch = JObject.Parse(JsonConvert.SerializeObject(await SendRequest(new HttpMethod(sHTTPVerb), sFullURI, arInvoiceBatch)));
                JArray invoices = (JArray)newBatch["Invoices"];
    
                string sBatchNumber = "";
    
                if (invoices != null)
                {
                    for (int i = 0; i < invoices.Count; i++)
                    {
                        foreach (JObject content in invoices.Children<JObject>())
                        {
                            foreach (JProperty prop in content.Properties())
                            {
                                string tempValue = (string)prop.Value;
                            }
                        }
                    }
    
                    sBatchNumber = (string)newBatch["BatchNumber"];

    Now, this gets the BatchNumber out which is in the header part of the JSON. Now I need to iterate through the invoices. The code I have above is partly from the NewtonSoft site and another coding forum. However, I am now stuck. So I suppose, 2 questions.

    1. Is there a way to get the dynamic newBatch JSON stored easily in an object if I create a class for it without writing tonnes of code?
    2. Or, how do I go about getting the Entry Number and Document Number from the JSON - these can be found on lines 21, 23, and 747, 749?

    It seems to me that doing loads of nested foreach loops to iterate through the JSON is not the right way to do it.

    Any help much appreciated.

    Monday, September 24, 2018 2:41 PM

Answers

  • User475983607 posted

    I built a sample from your post, using the Paste Special method above, and it works great.

    Rootobject data = JsonConvert.DeserializeObject<Rootobject>(File.ReadAllText(filePath));
    int batchNumber = data.BatchNumber;
    
    List<Invoice> invoices = (from d in data.Invoices
                                where d.BatchNumber == batchNumber
                                select d).ToList();
    
    foreach(Invoice i in invoices)
    {
        Console.WriteLine("{0} - {1}", i.BatchNumber, i.CustomerNumber);
        foreach(Invoicedetail d in i.InvoiceDetails)
        {
            Console.WriteLine("\t{0}", d.Description);
        }
    }
    166 - TESTREC2C
            AIR FREIGHT CHARGE
            AIR FREIGHT CHARGE
    166 - TESTREC3
            AIR FREIGHT CHARGE
            AIR FREIGHT CHARGE
    Press any key to continue . . .

    The only difference is I pulled the JSON from a file stream, highlighted, rather than an HTTP stream but it should not matter.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 28, 2018 4:42 PM

All replies

  • User475983607 posted

    Is there a way to get the dynamic newBatch JSON stored easily in an object if I create a class for it without writing tonnes of code?

    What is stopping you from simply serialization into a strongly typed object.  Visual Studio will create the C# class; eidt-> paste special -> paste JSON as classes.  Then just deserialize into the strongly typed class created by Visual Studio.  It's one line of code...

    Or, how do I go about getting the Entry Number and Document Number from the JSON - these can be found on lines 21, 23, and 747, 749?

    Once you have a strong type use linq or simply "dot " into the object model.

    Monday, September 24, 2018 2:53 PM
  • User-1458727574 posted

    AnyUserNameThatLetsMeIn

    Is there a way to get the dynamic newBatch JSON stored easily in an object if I create a class for it without writing tonnes of code?

    What is stopping you from simply serialization into a strongly typed object.  Visual Studio will create the C# class; eidt-> paste special -> paste JSON as classes.  Then just deserialize into the strongly typed class created by Visual Studio.  It's one line of code...

    I've used the paste special a lot and it is brilliant. I can create a class from the JSON data easily enough using that method, but every time I tried to get the dynamic newBatch stored into an object of that class, it wouldn't do it. I started reading up on it and I couldn't find a way to do it that worked. Every time I tried something it failed. I don't have the sites I visited any more so I can't really post anything to show. Assume I had a class called MyARInvoiceBatch how, in one line, would I convert the dynamic newBatch into an object of type MyARInvoiceBatch?

    AnyUserNameThatLetsMeIn

    Or, how do I go about getting the Entry Number and Document Number from the JSON - these can be found on lines 21, 23, and 747, 749?

    Once you have a strong type use linq or simply "dot " into the object model.

    I did start looking into Linq and I did manage to figure bits of it out but then I found the JObject and JArray and I thought they might suffice. I'm open to ideas. Ideally I can just copy the dynamic one into a strongly typed object.

    Monday, September 24, 2018 3:13 PM
  • User1724605321 posted

    Hi AnyUserNameThatLetsMeIn ,

    but every time I tried to get the dynamic newBatch stored into an object of that class, it wouldn't do it.

    What do you mean by "it wouldn't do it" . You can use vs extension or online json object convert to deserialize into the strongly typed class . You can also use Json.NET to return a dynamic object , see document : Querying JSON with dynamic .

    . Ideally I can just copy the dynamic one into a strongly typed object.

    Why not directly return strongly typed object ? Generally we prefer to use a strong type over a dynamic .

    Best Regards,

    Nan Yu

    Tuesday, September 25, 2018 2:38 AM
  • User-1458727574 posted

    Hi AnyUserNameThatLetsMeIn ,

    AnyUserNameThatLetsMeIn

    but every time I tried to get the dynamic newBatch stored into an object of that class, it wouldn't do it.

    What do you mean by "it wouldn't do it" . You can use vs extension or online json object convert to deserialize into the strongly typed class . You can also use Json.NET to return a dynamic object , see document : Querying JSON with dynamic .

    Every way I tried I got errors.

    AnyUserNameThatLetsMeIn

    . Ideally I can just copy the dynamic one into a strongly typed object.

    Why not directly return strongly typed object ? Generally we prefer to use a strong type over a dynamic .

    Best Regards,

    Nan Yu

    The JSON comes from an external application of which I have no control over. So, I get a JSON string and I would like to put it into an object. So hypothetically this:

    (I know this doesn't work)

    ARDynamicInvoiceBatch aRDynamicInvoiceBatch = new ARDynamicInvoiceBatch();
    
    aRDynamicInvoiceBatch = await SendRequest(new HttpMethod(sHTTPVerb), sFullURI, arInvoiceBatch);

    The SendRequest function definition is:

    public static async Task<object> SendRequest(HttpMethod method, string requestUri, object payload = null)

    So it returns an object. The reason being is that the application I'm calling can return different types for the same call depending on what happens, so the return from this function does this:

    return string.IsNullOrWhiteSpace(appResponse) ? null : JsonConvert.DeserializeObject(appResponse);

    So it is already deserialising to an object. I need to cast the returned object to an object of type ARDynamicInvoiceBatch. The error is:

    Cannot implicitly convert type 'object' to ARDynamicInvoiceBatch. An explicit conversion exists (are you missing a cast?)

    So casting that dynamic type to my ARDynamicInvoiceBatch object. I've tried. I cannot get the syntax right. What am I missing?

    Tuesday, September 25, 2018 9:28 AM
  • User-1458727574 posted

    Any thoughts on this?

    The function that sends the request into Sage returns a type of object because if the return generates an error, Sage returns a different object, so the return type is always dynamic. The last line of the function that puts the details into Sage deserialises it into an object which I pick up as a dynamic object on the return. How can I convert a dynamic object into a strongly typed one easily? Part of my issue is searching for things on the web when you're not clear on the terminology as I am still learning that as I go.

    So, I have a class that can take the dynamic object, but getting the data into it without doing a line by line copy of the values seems to be really tricky unless I'm missing something.

    Update:

    After a bit of messing around I now get an error message at least.

    An unhandled exception occurred while processing the request.

    <div class="titleerror">AggregateException: One or more errors occurred. (Cannot implicitly convert type 'Newtonsoft.Json.Linq.JObject' to 'ACLWebApi.CustomClasses.ARDynamicInvoiceBatch.ARDynamicInvoiceBatch')</div>

    Friday, September 28, 2018 3:20 PM
  • User475983607 posted

    I built a sample from your post, using the Paste Special method above, and it works great.

    Rootobject data = JsonConvert.DeserializeObject<Rootobject>(File.ReadAllText(filePath));
    int batchNumber = data.BatchNumber;
    
    List<Invoice> invoices = (from d in data.Invoices
                                where d.BatchNumber == batchNumber
                                select d).ToList();
    
    foreach(Invoice i in invoices)
    {
        Console.WriteLine("{0} - {1}", i.BatchNumber, i.CustomerNumber);
        foreach(Invoicedetail d in i.InvoiceDetails)
        {
            Console.WriteLine("\t{0}", d.Description);
        }
    }
    166 - TESTREC2C
            AIR FREIGHT CHARGE
            AIR FREIGHT CHARGE
    166 - TESTREC3
            AIR FREIGHT CHARGE
            AIR FREIGHT CHARGE
    Press any key to continue . . .

    The only difference is I pulled the JSON from a file stream, highlighted, rather than an HTTP stream but it should not matter.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 28, 2018 4:42 PM
  • User-1458727574 posted

    That's pretty much done it. Only minor changes needed for my code. Because the function already deserialises to an object of type object due to the Sage system returning different data structures from the same call, I can serialise it and then deserialise the output and cast it to the right object type. Fixed a few issues with datetime, int, and decimal values being null, but that seems to work for what I need.

    Thanks.

    Monday, October 1, 2018 10:51 AM