0

So I'm trying to access one specific field in a huge array of objects and having difficulties doing so. The field that I want is "date": ["20220408062804"], which is inside of an object within an object. What would the dot notation look like to do this?

I thought that it would be something like this:

const date = nm_response.transaction[0].action[0].date
    //     console.log('date' + date)

But it just returns undefined.

Here is the whole JSON response from api.

// {
//   "nm_response": {
//     "transaction": [
//       {
//         "transaction_id": ["7130815484"],
//         "partial_payment_id": [""],
//         "partial_payment_balance": [""],
//         "platform_id": [""],
//         "transaction_type": ["cc"],
//         "condition": ["pendingsettlement"],
//         "order_id": [""],
//         "authorization_code": ["123456"],
//         "ponumber": [""],
//         "order_description": [""],
//         "first_name": [""],
//         "last_name": [""],
//         "address_1": [""],
//         "address_2": [""],
//         "company": [""],
//         "city": [""],
//         "state": [""],
//         "postal_code": [""],
//         "country": [""],
//         "email": [""],
//         "phone": [""],
//         "fax": [""],
//         "cell_phone": [""],
//         "customertaxid": [""],
//         "customerid": ["895819143"],
//         "website": [""],
//         "shipping_first_name": [""],
//         "shipping_last_name": [""],
//         "shipping_address_1": [""],
//         "shipping_address_2": [""],
//         "shipping_company": [""],
//         "shipping_city": [""],
//         "shipping_state": [""],
//         "shipping_postal_code": [""],
//         "shipping_country": [""],
//         "shipping_email": [""],
//         "shipping_carrier": [""],
//         "tracking_number": [""],
//         "shipping_date": [""],
//         "shipping": ["0.00"],
//         "shipping_phone": [""],
//         "cc_number": ["4xxxxxxxxxxx1111"],
//         "cc_hash": ["f6c609e195d9d4c185dcc8ca662f0180"],
//         "cc_exp": ["1025"],
//         "cavv": [""],
//         "cavv_result": [""],
//         "xid": [""],
//         "eci": [""],
//         "directory_server_id": [""],
//         "three_ds_version": [""],
//         "avs_response": [""],
//         "csc_response": ["M"],
//         "cardholder_auth": [""],
//         "cc_start_date": [""],
//         "cc_issue_number": [""],
//         "check_account": [""],
//         "check_hash": [""],
//         "check_aba": [""],
//         "check_name": [""],
//         "account_holder_type": [""],
//         "account_type": [""],
//         "sec_code": [""],
//         "drivers_license_number": [""],
//         "drivers_license_state": [""],
//         "drivers_license_dob": [""],
//         "social_security_number": [""],
//         "processor_id": ["ccprocessora"],
//         "tax": ["0.00"],
//         "currency": ["USD"],
//         "surcharge": [""],
//         "cash_discount": [""],
//         "tip": [""],
//         "card_balance": [""],
//         "card_available_balance": [""],
//         "entry_mode": ["Keyed"],
//         "cc_bin": ["411111"],
//         "cc_type": ["Visa"],
//         "signature_image": [""],
//         "duty_amount": [""],
//         "discount_amount": [""],
//         "national_tax_amount": [""],
//         "summary_commodity_code": [""],
//         "vat_tax_amount": [""],
//         "vat_tax_rate": [""],
//         "alternate_tax_amount": [""],
//         "action": [
//           {
//             "amount": ["10.00"],
//             "action_type": ["sale"],
//             "date": ["20220408062804"],
//             "success": ["1"],
//             "ip_address": ["47.221.164.46"],
//             "source": ["api"],
//             "api_method": ["direct_post"],
//             "tap_to_mobile": ["false"],
//             "username": ["truthsandbox"],
//             "response_text": ["SUCCESS"],
//             "batch_id": ["0"],
//             "processor_batch_id": [""],
//             "response_code": ["100"],
//             "processor_response_text": [""],
//             "processor_response_code": [""],
//             "device_license_number": [""],
//             "device_nickname": [""]
//           }
//         ]
//       }
//     ]
//   }
// }
Barmar
  • 669,327
  • 51
  • 454
  • 560
HacAtac
  • 41
  • 6
  • you'll want to first parse that to a javascript object - then it'll be easy – Bravo May 06 '22 at 06:16
  • Why does the JSON have `//` at the beginning of each line? That won't parse correctly. – Barmar May 06 '22 at 06:17
  • `nm_response` isn't the variable, it's a property in the object. So it should start with `response.nm_response` – Barmar May 06 '22 at 06:18
  • console.log(js_val.nm_response.transaction[0].action[0].date); where js_val is the json value you gave – Faiz Sandhi May 06 '22 at 06:29
  • from where are you getting this json, tell me first – Faiz Sandhi May 06 '22 at 06:31
  • For sure, so it's an NMI gateway query that I've made to the customer_vault. It was originally returned as XML that I've parsed into JSON as it sent it back. Now I'm trying to pro rate subscriptions based off of when someone upgrades but I want the data key and value to do so. – HacAtac May 06 '22 at 06:56

0 Answers0