Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Valid JSON formatted response #428

Open
1 task done
ahkelly opened this issue Dec 22, 2023 · 6 comments
Open
1 task done

[Feat]: Valid JSON formatted response #428

ahkelly opened this issue Dec 22, 2023 · 6 comments
Labels
triage Issue is being researched

Comments

@ahkelly
Copy link

ahkelly commented Dec 22, 2023

Feature Request Is New

  • I have verified that the requested feature does not already exist or has not already been requested.

Description of the feature

Is there a way to request a valid JSON response from node requests, rather then having to convert the Object using:

JSON.parse(JSON.stringify(response))

Interestingly the docs show a valid JSON response but the api returns an object. Just wondering if there is or could be added a hidden flag to request JSON format.

@ahkelly ahkelly added the triage Issue is being researched label Dec 22, 2023
@nwithan8
Copy link
Member

nwithan8 commented Dec 23, 2023

Currently all our client libraries, including the Node one, are configured to deserialize the JSON responses from the API into in-memory objects.

Is there a particular use case you had in mind where accessing the raw JSON response rather than using the serialized object would be better?

@ahkelly
Copy link
Author

ahkelly commented Dec 26, 2023

I certainly understand the thinking on this but I am referring primarily to SSR requests that are returned via a promise to a page. For every other third party api's we use (stripe, paypal, database requests, etc) they all return JSON compatible objects by default. The easypost object returned is non-standard / non-serializable format so at a minimum it would be great to fix that and make it the same as the documentation. Below is an example returned from a rate request (client.Shipment.create)

Shipment {
  created_at: '2023-12-26T23:16:23Z',
  is_return: false,
  ...
}

Obviously this format is not a Plain Old Javascript Object

@bnbry
Copy link
Member

bnbry commented Dec 27, 2023

Hey @ahkelly, thanks for submitting this issue, I would like to try and better understand what you're running into.

We don't currently have a way to get a raw JSON string instead of the object but I'm hoping by better understanding the issue you're running into that you won't need that. A raw JSON string will still force you to do the JSON.parse and the response object we do return should act like any other plain old javascript object.

The raw JSON response from the API is converted to an object in the library. As far as I'm aware it is a valid javascript object and that is why you are able to stringify and parse it.

What I'm not sure about is what our current response is preventing you from doing.

This operation

JSON.parse(JSON.stringify(response))

should basically be a no-op and you should end up more or less with what you started with. It sounds like that is not the case and you are unable to do something with response that you can do once you stringify and parse. That is not intended on our side. Can you provide some code of how you are using the response that isn't working unless you parse/stringify? I think that will help us better understand the issue.

@ahkelly
Copy link
Author

ahkelly commented Dec 27, 2023

So I am using svelte/kit for the server side request

Full svelte sample load request code is below, this will throw a 500 error as the response cannot be parsed as valid JSON thus the stringify dance I note above to correct that. FYI, if you save the exact example from the docs to an app.js and run

node app.js 

you will get the exact same response as my svelte code below receives.

import EasyPostClient from '@easypost/api';
import { API_EASYPOST_SECRET_KEY_TEST } from '$env/static/private';

export async function load() {
	const client = new EasyPostClient(API_EASYPOST_SECRET_KEY_TEST);
	const easypost_shipment = await client.Shipment.create({
		from_address: {
			street1: '417 MONTGOMERY ST',
			street2: 'FLOOR 5',
			city: 'SAN FRANCISCO',
			state: 'CA',
			zip: '94104',
			country: 'US',
			company: 'EasyPost',
			phone: '415-123-4567'
		},
		to_address: {
			name: 'Dr. Steve Brule',
			street1: '179 N Harbor Dr',
			city: 'Redondo Beach',
			state: 'CA',
			zip: '90277',
			country: 'US',
			phone: '4155559999'
		},
		parcel: {
			length: 8,
			width: 5,
			height: 5,
			weight: 5
		}
	});
	console.log(easypost_shipment);
	return {
		easypost_shipment // will throw an error, need to use below code to workaround
                // easypost_shipment: JSON.stringify(easypost_shipment)
	};
}

Attempting to return this response as shown above will throw the following exception, essentially saying the svelte parser can't handle this non standard object

page {
  error: {
    message: 'There was an unexpected exception.',
    locals: {
      clientIpAddress: '::1',
      userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
    },
    error: SyntaxError: Unexpected token o in JSON at position 1
        at JSON.parse (<anonymous>)
 ......

The response object I get (dumped directly to the console from the node request)

Shipment {
  created_at: '2023-12-27T21:56:23Z',
  is_return: false,
  messages: [],
  mode: 'test',
  options: EasyPostObject {
    currency: 'USD',
    payment: EasyPostObject { type: 'SENDER', _params: [Object] },
    date_advance: 0,
    _params: { shipment: [Object] }
  },
  reference: null,
  status: 'unknown',
  tracking_code: null,
  updated_at: '2023-12-27T21:56:23Z',
  batch_id: null,
  batch_status: null,
  batch_message: null,
  customs_info: null,
  from_address: undefined {
    id: 'adr_c6cdfaeea50211eea1e3ac1f6bc539ae',
    object: 'Address',
    created_at: '2023-12-27T21:56:23+00:00',
    updated_at: '2023-12-27T21:56:23+00:00',
    name: null,
    company: 'EasyPost',
    street1: '417 MONTGOMERY ST',
    street2: 'FLOOR 5',
    city: 'SAN FRANCISCO',
    state: 'CA',
    zip: '94104',
    country: 'US',
    phone: '4151234567',
    email: null,
    mode: 'test',
    carrier_facility: null,
    residential: null,
    federal_tax_id: null,
    state_tax_id: null,
    verifications: EasyPostObject { _params: [Object] },
    _params: { shipment: [Object] }
  },
  insurance: null,
  order_id: null,
  parcel: Parcel {
    id: 'prcl_c57a0164d37d4f5c8fde55067ba7b8a2',
    object: 'Parcel',
    created_at: '2023-12-27T21:56:23Z',
    updated_at: '2023-12-27T21:56:23Z',
    length: 8,
    width: 5,
    height: 5,
    predefined_package: null,
    weight: 5,
    mode: 'test',
    _params: { shipment: [Object] }
  },
  postage_label: null,
  rates: [
    Rate {
      id: 'rate_4835e964d0df4a90ae83d9dade1ffdc9',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'Express',
      carrier: 'USPS',
      rate: '27.35',
      currency: 'USD',
      retail_rate: '31.20',
      retail_currency: 'USD',
      list_rate: '27.35',
      list_currency: 'USD',
      billing_type: 'easypost',
      delivery_days: null,
      delivery_date: null,
      delivery_date_guaranteed: false,
      est_delivery_days: null,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6d23b5ac2e5e431d9e29853ae679a260',
      _params: [Object]
    },
    Rate {
      id: 'rate_4592fa2a9c2f452c9b6064100a065975',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'Priority',
      carrier: 'USPS',
      rate: '6.95',
      currency: 'USD',
      retail_rate: '10.20',
      retail_currency: 'USD',
      list_rate: '8.24',
      list_currency: 'USD',
      billing_type: 'easypost',
      delivery_days: 2,
      delivery_date: null,
      delivery_date_guaranteed: false,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6d23b5ac2e5e431d9e29853ae679a260',
      _params: [Object]
    },
    Rate {
      id: 'rate_0d46da0163434da28df967e820e66440',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'GroundAdvantage',
      carrier: 'USPS',
      rate: '4.15',
      currency: 'USD',
      retail_rate: '5.60',
      retail_currency: 'USD',
      list_rate: '4.15',
      list_currency: 'USD',
      billing_type: 'easypost',
      delivery_days: 3,
      delivery_date: null,
      delivery_date_guaranteed: false,
      est_delivery_days: 3,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6d23b5ac2e5e431d9e29853ae679a260',
      _params: [Object]
    },
    Rate {
      id: 'rate_df3ec6aeb17642d0aadffb152d88a38b',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'First',
      carrier: 'USPS',
      rate: '4.15',
      currency: 'USD',
      retail_rate: '5.60',
      retail_currency: 'USD',
      list_rate: '4.15',
      list_currency: 'USD',
      billing_type: 'easypost',
      delivery_days: 3,
      delivery_date: null,
      delivery_date_guaranteed: false,
      est_delivery_days: 3,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6d23b5ac2e5e431d9e29853ae679a260',
      _params: [Object]
    },
    Rate {
      id: 'rate_78056871bcba42ee9648c5fe4e29b638',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'ParcelSelect',
      carrier: 'USPS',
      rate: '4.15',
      currency: 'USD',
      retail_rate: '5.60',
      retail_currency: 'USD',
      list_rate: '4.15',
      list_currency: 'USD',
      billing_type: 'easypost',
      delivery_days: 3,
      delivery_date: null,
      delivery_date_guaranteed: false,
      est_delivery_days: 3,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6d23b5ac2e5e431d9e29853ae679a260',
      _params: [Object]
    },
    Rate {
      id: 'rate_b7aea39fea5043bfabef8da5ad18286f',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'NextDayAir',
      carrier: 'UPS',
      rate: '95.94',
      currency: 'USD',
      retail_rate: '87.92',
      retail_currency: 'USD',
      list_rate: '91.08',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 1,
      delivery_date: '2023-12-28T15:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 1,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_23afe786d2c64baa8c45d84e182af912',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: '2ndDayAir',
      carrier: 'UPS',
      rate: '31.00',
      currency: 'USD',
      retail_rate: '29.26',
      retail_currency: 'USD',
      list_rate: '29.69',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 2,
      delivery_date: '2023-12-29T23:00:00Z',
      delivery_date_guaranteed: false,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_9b36daa759114dc1b8742308c1a99df1',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'Ground',
      carrier: 'UPS',
      rate: '15.89',
      currency: 'USD',
      retail_rate: '14.88',
      retail_currency: 'USD',
      list_rate: '15.14',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 2,
      delivery_date: '2023-12-29T23:00:00Z',
      delivery_date_guaranteed: false,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_e7832f64f9024aae962487810e0545ae',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: '3DaySelect',
      carrier: 'UPS',
      rate: '23.46',
      currency: 'USD',
      retail_rate: '22.31',
      retail_currency: 'USD',
      list_rate: '22.67',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 3,
      delivery_date: '2024-01-02T23:00:00Z',
      delivery_date_guaranteed: false,
      est_delivery_days: 3,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_2ed8c89341c845d485092ca8abc06107',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'NextDayAirSaver',
      carrier: 'UPS',
      rate: '87.57',
      currency: 'USD',
      retail_rate: '82.76',
      retail_currency: 'USD',
      list_rate: '83.13',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 1,
      delivery_date: '2023-12-28T23:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 1,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_cdc987a997824bb0bffa97c7a58a6044',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'NextDayAirEarlyAM',
      carrier: 'UPS',
      rate: '130.18',
      currency: 'USD',
      retail_rate: '122.50',
      retail_currency: 'USD',
      list_rate: '125.66',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 1,
      delivery_date: '2023-12-28T09:30:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 1,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_8c3aca30d10b42f1b1f9ec68a58c5c97',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: '2ndDayAirAM',
      carrier: 'UPS',
      rate: '35.68',
      currency: 'USD',
      retail_rate: '33.13',
      retail_currency: 'USD',
      list_rate: '33.40',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 2,
      delivery_date: '2023-12-29T23:00:00Z',
      delivery_date_guaranteed: false,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_14d11b400e9541eaa9acaeea803cb727',
      _params: [Object]
    },
    Rate {
      id: 'rate_e303756ae02a4469a1c8251a2786a165',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'FIRST_OVERNIGHT',
      carrier: 'FedEx',
      rate: '125.88',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '125.88',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 1,
      delivery_date: '2023-12-28T10:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 1,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    },
    Rate {
      id: 'rate_7911bf44feae4b1290fb0f5b74c67c5d',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'PRIORITY_OVERNIGHT',
      carrier: 'FedEx',
      rate: '67.61',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '90.15',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 1,
      delivery_date: '2023-12-28T12:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 1,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    },
    Rate {
      id: 'rate_5754e365269a418ab468e23a9fe30135',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'STANDARD_OVERNIGHT',
      carrier: 'FedEx',
      rate: '45.27',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '82.30',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 1,
      delivery_date: '2023-12-28T17:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 1,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    },
    Rate {
      id: 'rate_99d20ffca9974455879aec1f6d396949',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'FEDEX_2_DAY_AM',
      carrier: 'FedEx',
      rate: '21.98',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '34.10',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 2,
      delivery_date: '2023-12-29T10:30:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    },
    Rate {
      id: 'rate_7975323a0db14b7b956663824728a1c1',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'FEDEX_2_DAY',
      carrier: 'FedEx',
      rate: '19.75',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '29.39',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 2,
      delivery_date: '2023-12-29T17:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    },
    Rate {
      id: 'rate_d3d72be4f0fa426b87eaf6f5d0dc96b8',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'FEDEX_GROUND',
      carrier: 'FedEx',
      rate: '11.64',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '15.11',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 2,
      delivery_date: '2023-12-29T23:59:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 2,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    },
    Rate {
      id: 'rate_a2cba6fbf401490fa7286b98a65ad10f',
      object: 'Rate',
      created_at: '2023-12-27T21:56:25Z',
      updated_at: '2023-12-27T21:56:25Z',
      mode: 'test',
      service: 'FEDEX_EXPRESS_SAVER',
      carrier: 'FedEx',
      rate: '18.71',
      currency: 'USD',
      retail_rate: null,
      retail_currency: null,
      list_rate: '25.71',
      list_currency: 'USD',
      billing_type: 'carrier',
      delivery_days: 6,
      delivery_date: '2024-01-02T17:00:00Z',
      delivery_date_guaranteed: true,
      est_delivery_days: 6,
      shipment_id: 'shp_eeffabbc19d64c0daf113244a82274ef',
      carrier_account_id: 'ca_6df49f3ff6374a92ab9c5ae7724d2863',
      _params: [Object]
    }
  ],
  refund_status: null,
  scan_form: null,
  selected_rate: null,
  tracker: null,
  to_address: undefined {
    id: 'adr_c6cad097a50211eea1e2ac1f6bc539ae',
    object: 'Address',
    created_at: '2023-12-27T21:56:23+00:00',
    updated_at: '2023-12-27T21:56:23+00:00',
    name: 'Dr. Steve Brule',
    company: null,
    street1: '179 N Harbor Dr',
    street2: null,
    city: 'Redondo Beach',
    state: 'CA',
    zip: '90277',
    country: 'US',
    phone: '4155559999',
    email: null,
    mode: 'test',
    carrier_facility: null,
    residential: null,
    federal_tax_id: null,
    state_tax_id: null,
    verifications: EasyPostObject { _params: [Object] },
    _params: { shipment: [Object] }
  },
  usps_zone: 4,
  return_address: undefined {
    id: 'adr_c6cdfaeea50211eea1e3ac1f6bc539ae',
    object: 'Address',
    created_at: '2023-12-27T21:56:23+00:00',
    updated_at: '2023-12-27T21:56:23+00:00',
    name: null,
    company: 'EasyPost',
    street1: '417 MONTGOMERY ST',
    street2: 'FLOOR 5',
    city: 'SAN FRANCISCO',
    state: 'CA',
    zip: '94104',
    country: 'US',
    phone: '4151234567',
    email: null,
    mode: 'test',
    carrier_facility: null,
    residential: null,
    federal_tax_id: null,
    state_tax_id: null,
    verifications: EasyPostObject { _params: [Object] },
    _params: { shipment: [Object] }
  },
  buyer_address: undefined {
    id: 'adr_c6cad097a50211eea1e2ac1f6bc539ae',
    object: 'Address',
    created_at: '2023-12-27T21:56:23+00:00',
    updated_at: '2023-12-27T21:56:23+00:00',
    name: 'Dr. Steve Brule',
    company: null,
    street1: '179 N Harbor Dr',
    street2: null,
    city: 'Redondo Beach',
    state: 'CA',
    zip: '90277',
    country: 'US',
    phone: '4155559999',
    email: null,
    mode: 'test',
    carrier_facility: null,
    residential: null,
    federal_tax_id: null,
    state_tax_id: null,
    verifications: EasyPostObject { _params: [Object] },
    _params: { shipment: [Object] }
  },
  forms: [],
  fees: [],
  id: 'shp_eeffabbc19d64c0daf113244a82274ef',
  object: 'Shipment',
  _params: {
    shipment: { from_address: [Object], to_address: [Object], parcel: [Object] }
  }
}

Further to your query regarding stringifying the response. As you can see above this is not a valid parseable object by JSON.parse so stringifying it fixes the weird format which opens with an orphan "Shipment" and adds quotes around all data names and turning above non-standard object into below.

{
  "created_at": "2023-12-27T22:11:11Z",
  "is_return": false,
  "messages": [],
  "mode": "test",
  "options": {
    "currency": "USD",
    "payment": {
      "type": "SENDER",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    "date_advance": 0,
    "_params": {
      "shipment": {
        "from_address": {
          "street1": "417 MONTGOMERY ST",
          "street2": "FLOOR 5",
          "city": "SAN FRANCISCO",
          "state": "CA",
          "zip": "94104",
          "country": "US",
          "company": "EasyPost",
          "phone": "415-123-4567"
        },
        "to_address": {
          "name": "Dr. Steve Brule",
          "street1": "179 N Harbor Dr",
          "city": "Redondo Beach",
          "state": "CA",
          "zip": "90277",
          "country": "US",
          "phone": "4155559999"
        },
        "parcel": {
          "length": 8,
          "width": 5,
          "height": 5,
          "weight": 5
        }
      }
    }
  },
  "reference": null,
  "status": "unknown",
  "tracking_code": null,
  "updated_at": "2023-12-27T22:11:11Z",
  "batch_id": null,
  "batch_status": null,
  "batch_message": null,
  "customs_info": null,
  "from_address": {
    "id": "adr_d8074de7a50411eeab9aac1f6bc539aa",
    "object": "Address",
    "created_at": "2023-12-27T22:11:11+00:00",
    "updated_at": "2023-12-27T22:11:11+00:00",
    "name": null,
    "company": "EasyPost",
    "street1": "417 MONTGOMERY ST",
    "street2": "FLOOR 5",
    "city": "SAN FRANCISCO",
    "state": "CA",
    "zip": "94104",
    "country": "US",
    "phone": "4151234567",
    "email": null,
    "mode": "test",
    "carrier_facility": null,
    "residential": null,
    "federal_tax_id": null,
    "state_tax_id": null,
    "verifications": {
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    "_params": {
      "shipment": {
        "from_address": {
          "street1": "417 MONTGOMERY ST",
          "street2": "FLOOR 5",
          "city": "SAN FRANCISCO",
          "state": "CA",
          "zip": "94104",
          "country": "US",
          "company": "EasyPost",
          "phone": "415-123-4567"
        },
        "to_address": {
          "name": "Dr. Steve Brule",
          "street1": "179 N Harbor Dr",
          "city": "Redondo Beach",
          "state": "CA",
          "zip": "90277",
          "country": "US",
          "phone": "4155559999"
        },
        "parcel": {
          "length": 8,
          "width": 5,
          "height": 5,
          "weight": 5
        }
      }
    }
  },
  "insurance": null,
  "order_id": null,
  "parcel": {
    "id": "prcl_a5e0148028894db49c3046b49b03f66e",
    "object": "Parcel",
    "created_at": "2023-12-27T22:11:11Z",
    "updated_at": "2023-12-27T22:11:11Z",
    "length": 8,
    "width": 5,
    "height": 5,
    "predefined_package": null,
    "weight": 5,
    "mode": "test",
    "_params": {
      "shipment": {
        "from_address": {
          "street1": "417 MONTGOMERY ST",
          "street2": "FLOOR 5",
          "city": "SAN FRANCISCO",
          "state": "CA",
          "zip": "94104",
          "country": "US",
          "company": "EasyPost",
          "phone": "415-123-4567"
        },
        "to_address": {
          "name": "Dr. Steve Brule",
          "street1": "179 N Harbor Dr",
          "city": "Redondo Beach",
          "state": "CA",
          "zip": "90277",
          "country": "US",
          "phone": "4155559999"
        },
        "parcel": {
          "length": 8,
          "width": 5,
          "height": 5,
          "weight": 5
        }
      }
    }
  },
  "postage_label": null,
  "rates": [
    {
      "id": "rate_cfa68277ed6b4ed6b390e714c2325ee4",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "Priority",
      "carrier": "USPS",
      "rate": "6.95",
      "currency": "USD",
      "retail_rate": "10.20",
      "retail_currency": "USD",
      "list_rate": "8.24",
      "list_currency": "USD",
      "billing_type": "easypost",
      "delivery_days": 2,
      "delivery_date": null,
      "delivery_date_guaranteed": false,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6d23b5ac2e5e431d9e29853ae679a260",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_89554927bcf344f58ff28ce18fb2a76e",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "GroundAdvantage",
      "carrier": "USPS",
      "rate": "4.15",
      "currency": "USD",
      "retail_rate": "5.60",
      "retail_currency": "USD",
      "list_rate": "4.15",
      "list_currency": "USD",
      "billing_type": "easypost",
      "delivery_days": 3,
      "delivery_date": null,
      "delivery_date_guaranteed": false,
      "est_delivery_days": 3,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6d23b5ac2e5e431d9e29853ae679a260",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_898fcd15730a4dbf8dca628132edacc5",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "First",
      "carrier": "USPS",
      "rate": "4.15",
      "currency": "USD",
      "retail_rate": "5.60",
      "retail_currency": "USD",
      "list_rate": "4.15",
      "list_currency": "USD",
      "billing_type": "easypost",
      "delivery_days": 3,
      "delivery_date": null,
      "delivery_date_guaranteed": false,
      "est_delivery_days": 3,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6d23b5ac2e5e431d9e29853ae679a260",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_e8653ca24ff242658554d1c48be14752",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "ParcelSelect",
      "carrier": "USPS",
      "rate": "4.15",
      "currency": "USD",
      "retail_rate": "5.60",
      "retail_currency": "USD",
      "list_rate": "4.15",
      "list_currency": "USD",
      "billing_type": "easypost",
      "delivery_days": 3,
      "delivery_date": null,
      "delivery_date_guaranteed": false,
      "est_delivery_days": 3,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6d23b5ac2e5e431d9e29853ae679a260",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_88a34681c3b84542837196e06034541e",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "Express",
      "carrier": "USPS",
      "rate": "27.35",
      "currency": "USD",
      "retail_rate": "31.20",
      "retail_currency": "USD",
      "list_rate": "27.35",
      "list_currency": "USD",
      "billing_type": "easypost",
      "delivery_days": null,
      "delivery_date": null,
      "delivery_date_guaranteed": false,
      "est_delivery_days": null,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6d23b5ac2e5e431d9e29853ae679a260",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_3ab681bfbcf346c18114cf0470cc1b32",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "NextDayAir",
      "carrier": "UPS",
      "rate": "95.94",
      "currency": "USD",
      "retail_rate": "87.92",
      "retail_currency": "USD",
      "list_rate": "91.08",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 1,
      "delivery_date": "2023-12-28T15:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 1,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_276461419fd645d3a2cb3e6cc5a4e951",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "2ndDayAir",
      "carrier": "UPS",
      "rate": "31.00",
      "currency": "USD",
      "retail_rate": "29.26",
      "retail_currency": "USD",
      "list_rate": "29.69",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 2,
      "delivery_date": "2023-12-29T23:00:00Z",
      "delivery_date_guaranteed": false,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_2bc0dfda91134146b79d1578be765dbf",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "Ground",
      "carrier": "UPS",
      "rate": "15.89",
      "currency": "USD",
      "retail_rate": "14.88",
      "retail_currency": "USD",
      "list_rate": "15.14",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 2,
      "delivery_date": "2023-12-29T23:00:00Z",
      "delivery_date_guaranteed": false,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_00dd36b7b0ed4c74a88c46d674f6b854",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "3DaySelect",
      "carrier": "UPS",
      "rate": "23.46",
      "currency": "USD",
      "retail_rate": "22.31",
      "retail_currency": "USD",
      "list_rate": "22.67",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 3,
      "delivery_date": "2024-01-02T23:00:00Z",
      "delivery_date_guaranteed": false,
      "est_delivery_days": 3,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_e24327006a8546f0a5bd6b6408867690",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "NextDayAirSaver",
      "carrier": "UPS",
      "rate": "87.57",
      "currency": "USD",
      "retail_rate": "82.76",
      "retail_currency": "USD",
      "list_rate": "83.13",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 1,
      "delivery_date": "2023-12-28T23:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 1,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_14e44d51326e4e69a082bca02da753f3",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "NextDayAirEarlyAM",
      "carrier": "UPS",
      "rate": "130.18",
      "currency": "USD",
      "retail_rate": "122.50",
      "retail_currency": "USD",
      "list_rate": "125.66",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 1,
      "delivery_date": "2023-12-28T09:30:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 1,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_02a998205004475b9293feafd775db16",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "2ndDayAirAM",
      "carrier": "UPS",
      "rate": "35.68",
      "currency": "USD",
      "retail_rate": "33.13",
      "retail_currency": "USD",
      "list_rate": "33.40",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 2,
      "delivery_date": "2023-12-29T23:00:00Z",
      "delivery_date_guaranteed": false,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_14d11b400e9541eaa9acaeea803cb727",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_099c94e0353c4ac6a653c16d56354704",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "FIRST_OVERNIGHT",
      "carrier": "FedEx",
      "rate": "125.88",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "125.88",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 1,
      "delivery_date": "2023-12-28T10:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 1,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_9c68352f585f40ce9525a8df77350c87",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "PRIORITY_OVERNIGHT",
      "carrier": "FedEx",
      "rate": "67.61",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "90.15",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 1,
      "delivery_date": "2023-12-28T12:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 1,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_6331021d2f174cf682be4b74812af681",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "STANDARD_OVERNIGHT",
      "carrier": "FedEx",
      "rate": "45.27",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "82.30",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 1,
      "delivery_date": "2023-12-28T17:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 1,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_9fdabc8b8adc4739b71a5fc5680a5bf0",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "FEDEX_2_DAY_AM",
      "carrier": "FedEx",
      "rate": "21.98",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "34.10",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 2,
      "delivery_date": "2023-12-29T10:30:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_e852dbe47723485182cb3e5f7eb6ff83",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "FEDEX_2_DAY",
      "carrier": "FedEx",
      "rate": "19.75",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "29.39",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 2,
      "delivery_date": "2023-12-29T17:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_99457836c4da441daad527d4f8f433d0",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "FEDEX_GROUND",
      "carrier": "FedEx",
      "rate": "11.64",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "15.11",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 2,
      "delivery_date": "2023-12-29T23:59:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 2,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    {
      "id": "rate_566a611c8d944a788f3e510041e4ed86",
      "object": "Rate",
      "created_at": "2023-12-27T22:11:13Z",
      "updated_at": "2023-12-27T22:11:13Z",
      "mode": "test",
      "service": "FEDEX_EXPRESS_SAVER",
      "carrier": "FedEx",
      "rate": "18.71",
      "currency": "USD",
      "retail_rate": null,
      "retail_currency": null,
      "list_rate": "25.71",
      "list_currency": "USD",
      "billing_type": "carrier",
      "delivery_days": 6,
      "delivery_date": "2024-01-02T17:00:00Z",
      "delivery_date_guaranteed": true,
      "est_delivery_days": 6,
      "shipment_id": "shp_3b7357a9131b42e392d8371538409c82",
      "carrier_account_id": "ca_6df49f3ff6374a92ab9c5ae7724d2863",
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    }
  ],
  "refund_status": null,
  "scan_form": null,
  "selected_rate": null,
  "tracker": null,
  "to_address": {
    "id": "adr_d804af95a50411ee93d8ac1f6bc53342",
    "object": "Address",
    "created_at": "2023-12-27T22:11:11+00:00",
    "updated_at": "2023-12-27T22:11:11+00:00",
    "name": "Dr. Steve Brule",
    "company": null,
    "street1": "179 N Harbor Dr",
    "street2": null,
    "city": "Redondo Beach",
    "state": "CA",
    "zip": "90277",
    "country": "US",
    "phone": "4155559999",
    "email": null,
    "mode": "test",
    "carrier_facility": null,
    "residential": null,
    "federal_tax_id": null,
    "state_tax_id": null,
    "verifications": {
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    "_params": {
      "shipment": {
        "from_address": {
          "street1": "417 MONTGOMERY ST",
          "street2": "FLOOR 5",
          "city": "SAN FRANCISCO",
          "state": "CA",
          "zip": "94104",
          "country": "US",
          "company": "EasyPost",
          "phone": "415-123-4567"
        },
        "to_address": {
          "name": "Dr. Steve Brule",
          "street1": "179 N Harbor Dr",
          "city": "Redondo Beach",
          "state": "CA",
          "zip": "90277",
          "country": "US",
          "phone": "4155559999"
        },
        "parcel": {
          "length": 8,
          "width": 5,
          "height": 5,
          "weight": 5
        }
      }
    }
  },
  "usps_zone": 4,
  "return_address": {
    "id": "adr_d8074de7a50411eeab9aac1f6bc539aa",
    "object": "Address",
    "created_at": "2023-12-27T22:11:11+00:00",
    "updated_at": "2023-12-27T22:11:11+00:00",
    "name": null,
    "company": "EasyPost",
    "street1": "417 MONTGOMERY ST",
    "street2": "FLOOR 5",
    "city": "SAN FRANCISCO",
    "state": "CA",
    "zip": "94104",
    "country": "US",
    "phone": "4151234567",
    "email": null,
    "mode": "test",
    "carrier_facility": null,
    "residential": null,
    "federal_tax_id": null,
    "state_tax_id": null,
    "verifications": {
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    "_params": {
      "shipment": {
        "from_address": {
          "street1": "417 MONTGOMERY ST",
          "street2": "FLOOR 5",
          "city": "SAN FRANCISCO",
          "state": "CA",
          "zip": "94104",
          "country": "US",
          "company": "EasyPost",
          "phone": "415-123-4567"
        },
        "to_address": {
          "name": "Dr. Steve Brule",
          "street1": "179 N Harbor Dr",
          "city": "Redondo Beach",
          "state": "CA",
          "zip": "90277",
          "country": "US",
          "phone": "4155559999"
        },
        "parcel": {
          "length": 8,
          "width": 5,
          "height": 5,
          "weight": 5
        }
      }
    }
  },
  "buyer_address": {
    "id": "adr_d804af95a50411ee93d8ac1f6bc53342",
    "object": "Address",
    "created_at": "2023-12-27T22:11:11+00:00",
    "updated_at": "2023-12-27T22:11:11+00:00",
    "name": "Dr. Steve Brule",
    "company": null,
    "street1": "179 N Harbor Dr",
    "street2": null,
    "city": "Redondo Beach",
    "state": "CA",
    "zip": "90277",
    "country": "US",
    "phone": "4155559999",
    "email": null,
    "mode": "test",
    "carrier_facility": null,
    "residential": null,
    "federal_tax_id": null,
    "state_tax_id": null,
    "verifications": {
      "_params": {
        "shipment": {
          "from_address": {
            "street1": "417 MONTGOMERY ST",
            "street2": "FLOOR 5",
            "city": "SAN FRANCISCO",
            "state": "CA",
            "zip": "94104",
            "country": "US",
            "company": "EasyPost",
            "phone": "415-123-4567"
          },
          "to_address": {
            "name": "Dr. Steve Brule",
            "street1": "179 N Harbor Dr",
            "city": "Redondo Beach",
            "state": "CA",
            "zip": "90277",
            "country": "US",
            "phone": "4155559999"
          },
          "parcel": {
            "length": 8,
            "width": 5,
            "height": 5,
            "weight": 5
          }
        }
      }
    },
    "_params": {
      "shipment": {
        "from_address": {
          "street1": "417 MONTGOMERY ST",
          "street2": "FLOOR 5",
          "city": "SAN FRANCISCO",
          "state": "CA",
          "zip": "94104",
          "country": "US",
          "company": "EasyPost",
          "phone": "415-123-4567"
        },
        "to_address": {
          "name": "Dr. Steve Brule",
          "street1": "179 N Harbor Dr",
          "city": "Redondo Beach",
          "state": "CA",
          "zip": "90277",
          "country": "US",
          "phone": "4155559999"
        },
        "parcel": {
          "length": 8,
          "width": 5,
          "height": 5,
          "weight": 5
        }
      }
    }
  },
  "forms": [],
  "fees": [],
  "id": "shp_3b7357a9131b42e392d8371538409c82",
  "object": "Shipment",
  "_params": {
    "shipment": {
      "from_address": {
        "street1": "417 MONTGOMERY ST",
        "street2": "FLOOR 5",
        "city": "SAN FRANCISCO",
        "state": "CA",
        "zip": "94104",
        "country": "US",
        "company": "EasyPost",
        "phone": "415-123-4567"
      },
      "to_address": {
        "name": "Dr. Steve Brule",
        "street1": "179 N Harbor Dr",
        "city": "Redondo Beach",
        "state": "CA",
        "zip": "90277",
        "country": "US",
        "phone": "4155559999"
      },
      "parcel": {
        "length": 8,
        "width": 5,
        "height": 5,
        "weight": 5
      }
    }
  }
}

@bnbry
Copy link
Member

bnbry commented Dec 27, 2023

So I think I understand the confusion around "non standard object". I was considering class syntax to be standard but the issue is that it needs to be a truly plain object. The console dump you are seeing is a standard modern JS class object, it uses the class declaration syntax.

class Shipment {}

bare_shipment = {}
class_shipment = new Shipment()

class_shipment["valid_key"] = "some value"
bare_shipment["valid_key"] = "some value"

console.log(class_shipment)
console.log(bare_shipment)

would result in

Shipment {valid_key: 'some value'}
{valid_key: 'some value'}

I was considering them plain old javascript objects but there are differences between an instance of a class and a truly plain object that are impacting the sveltekit parser, which is a library called devalue.

The error you shared error: SyntaxError: Unexpected token o in JSON at position 1 happens when you try to call JSON.parse on an object after the parser calls toString() and gets the default "[object Object]" instead of a JSON string. I'm not sure how that is surfacing, maybe sveltekit has some fallback to JSON.parse if devalue fails, but I would expect to see Cannot stringify arbitrary non-POJOs (...) coming from devalue.

return {
  easypost_shipment,
}

would return a complete javascript object that does not need any specific handling but the problem is in how sveltekit serializes and that it rejects javascript classes as "arbitrary non-POJOs" based on their prototype.

The solution you have is actually the suggested work around from other sveltekit devs that have run into this with various libraries.

return {
  easypost_shipment: JSON.parse(JSON.stringify(easypost_shipment))
}

Or if you are on a recent version of node

return {
  easypost_shipment: structuredClone(easypost_shipment)
}

Thanks for reporting this issue, we don't use sveltekit in house and hadn't run into it. We will evaluate potentially moving away from JS classes because of this issue but that would need to be planned since all of our objects use class syntax today.

Unfortunately for now you'll need to do the conversion work around using one of the above methods in order to use the server load function in sveltekit.

@ahkelly
Copy link
Author

ahkelly commented Dec 28, 2023

Thanks for the explanation and understood. Did not occur to me you were returning this object as stripe, mailchimp, etc, etc all return standard JSON objects. I would offer it may be helpful to put this in the docs and update all your examples as they all show a standard JSON format as the response not a class object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Issue is being researched
Projects
None yet
Development

No branches or pull requests

3 participants