PrimeAcademy / biscayne-syllabus

1 stars 4 forks source link

Unable to populate PostgresSQL table with JSON data #2

Closed NekkidBear closed 4 months ago

NekkidBear commented 4 months ago

Description

Over the weekend I was able to get some sample JSON data from my API. However, when I try to run my script to parse the JSON and populate the table in Postico, I get an error indicating that my columns and values aren't matching up.

Your Real Name

Jason King-Lowe

What do you want to happen? I want it to parse the data returned in the JSON file and store it in the appropriate "restaurants" table field. I have the results for Minneapolis and St. Paul, as well as each restaurant's data

What is actually happening?

It fails on the first record. If I try to include other records and include a bypass to skip problematic records, it fails on each subsequent line.

Screenshots / Code Snippets

restaurantValues: [
  '828111',
  'Holy Land Bakery, Grocery and Deli',
  '45.013634',
  '-93.24711',
  '1491',
  'America/Chicago',
  'Minneapolis, Minnesota',
  '{"images":{"small":{"width":"250","url":"https://media-cdn.tripadvisor.com/media/photo-f/0b/a8/50/c1/wood-fire-rotisserie.jpg","height":"141"},"thumbnail":{"width":"50","url":"https://media-cdn.tripadvisor.com/media/photo-t/0b/a8/50/c1/wood-fire-rotisserie.jpg","height":"50"},"original":{"width":"1920","url":"https://media-cdn.tripadvisor.com/media/photo-o/0b/a8/50/c1/wood-fire-rotisserie.jpg","height":"1080"},"large":{"width":"1024","url":"https://media-cdn.tripadvisor.com/media/photo-w/0b/a8/50/c1/wood-fire-rotisserie.jpg","height":"576"},"medium":{"width":"550","url":"https://media-cdn.tripadvisor.com/media/photo-s/0b/a8/50/c1/wood-fire-rotisserie.jpg","height":"309"}},"is_blessed":true,"uploaded_date":"2016-06-18T12:34:34-0400","caption":"WOOD FIRE ROTISSERIE CHICKEN","id":"195580097","helpful_votes":"4","published_date":"2016-06-18T12:34:34-0400","user":{"user_id":null,"member_id":"0","type":"user"}}',
  'https://api.tripadvisor.com/api/internal/1.14/location/828111',
  '[]',
  'na.us.mn.minneapolis',
  'default',
  '4.893709182739258',
  'Minneapolis',
  '43323',
  '1',
  '1097',
  'restaurant',
  '#1 of 1,402 Restaurants in Minneapolis',
  null,
  null,
  null,
  '5.0',
  false,
  'Open Now',
  false,
  '$$ - $$$',
  '$1 - $20',
  undefined,
  'over 25 years of excellence our award winning restaurant has been serving the twin cities with the best meddle eastern food using Mama Fatima original recipes , and providing them with the largest selections of fresh bread , olives , cheeses , olive oil and finest imported grocery items , our meat department offers all 100% grass fed lamb , goat and beef with the highest quality available in the market (best of the best ) all HALAL-ZABIHA CERTIFIED.',
  'https://www.tripadvisor.com/Restaurant_Review-g43323-d828111-Reviews-Holy_Land_Bakery_Grocery_and_Deli-Minneapolis_Minnesota.html',
  'https://www.tripadvisor.com/UserReview-g43323-d828111-Holy_Land_Bakery_Grocery_and_Deli-Minneapolis_Minnesota.html',
  '[{"subcategory":[{"key":"city","name":"City"}],"name":"Minneapolis","abbrv":null,"location_id":"43323"},{"subcategory":[{"key":"state","name":"State"}],"name":"Minnesota","abbrv":"MN","location_id":"28944"},{"subcategory":[{"key":"country","name":"Country"}],"name":"United States","abbrv":null,"location_id":"191"}]',
  '{"key":"restaurant","name":"Restaurant"}',
  '[{"key":"fast_food","name":"Fast food"}]',
  'Minneapolis',
  false,
  '[]',
  '+1 612-781-2627',
  'http://www.holylandbrand.com/',
  'info@holylandbrand.com',
  '{"street1":"2513 Central Ave NE","street2":"","city":"Minneapolis","state":"MN","country":"United States","postalcode":"55418-3725"}',
  '2513 Central Ave NE, Minneapolis, MN 55418-3725',
  '{"week_ranges":[[{"open_time":540,"close_time":1260}],[{"open_time":540,"close_time":1260}],[{"open_time":540,"close_time":1260}],[{"open_time":540,"close_time":1260}],[{"open_time":540,"close_time":1260}],[{"open_time":540,"close_time":1260}],[{"open_time":540,"close_time":1260}]],"timezone":"America/Chicago"}',
  false,
  '[{"key":"10649","name":"Mediterranean"},{"key":"10679","name":"Healthy"},{"key":"10687","name":"Middle Eastern"},{"key":"11744","name":"Arabic"},{"key":"10665","name":"Vegetarian Friendly"},{"key":"10697","name":"Vegan Options"},{"key":"10751","name":"Halal"},{"key":"10992","name":"Gluten Free Options"}]',
  '[{"key":"10665","name":"Vegetarian Friendly"},{"key":"10697","name":"Vegan Options"},{"key":"10751","name":"Halal"},{"key":"10992","name":"Gluten Free Options"}]',
  '{"provider":"Grubhub","url":"https://www.tripadvisor.com/Commerce?p=Grubhub&src=181362556&geo=828111&from=api&area=reservation_button&slot=1&matchID=1&oos=0&cnt=1&silo=25768&bucket=852508&nrank=1&crank=1&clt=R&ttype=Restaurant&tm=295965912&managed=false&capped=false&gosox=I-ADlg7wY8lqEq92hGOCPH9yxKao4fnJtoYdd5TLctoCVK2EaqcCi9rOMrUCyEbyubmcsAgInVmLRZuDYYFIDJGjHFHZv0Zg9Ro4qxPoKyU&cs=18f6b60c618d857d05c68a61ae853a128"}',
  '{"id":"828111","provider":"Grubhub","provider_img":"https://static.tacdn.com/img2/branding/hotels/grubhub_05.11.2022.png","url":"https://www.tripadvisor.com/Commerce?p=Grubhub&src=181362556&geo=828111&from=api&area=reservation_button&slot=1&matchID=1&oos=0&cnt=1&silo=25768&bucket=852508&nrank=1&crank=1&clt=R&ttype=Restaurant&tm=295965912&managed=false&capped=false&gosox=I-ADlg7wY8lqEq92hGOCPH9yxKao4fnJtoYdd5TLctoCVK2EaqcCi9rOMrUCyEbyubmcsAgInVmLRZuDYYFIDJGjHFHZv0Zg9Ro4qxPoKyU&cs=18f6b60c618d857d05c68a61ae853a128","booking_partner_id":null,"racable":false,"api_bookable":false,"timeslots":null,"bestoffer":null,"timeslot_offers":null,"button_text":"Order Online","disclaimer_text":null,"banner_text":null}',
  '[{"key":"10591","name":"Restaurants"},{"key":"16548","name":"Specialty Food Market"}]'
]
Error inserting data: error: INSERT has more target columns than expressions
    at /Users/jasonking-lowe/Documents/primeHomework/SupprThyme/node_modules/pg/lib/client.js:526:17
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async insertSingleRestaurant (/Users/jasonking-lowe/Documents/primeHomework/SupprThyme/test_data/populateTestData.js:211:7)
    at async insertRestaurantData (/Users/jasonking-lowe/Documents/primeHomework/SupprThyme/test_data/populateTestData.js:214:5)

What did you try? Who did you ask?

I have double-checked the field names and structure in my SQL and the JSON and tried adding/modifying columns, but it hasn't helped.

I also consulted Google and copied my script and a sample JSON record into ChatGPT for troubleshooting assistance, but their suggestions were unhelpful. They just indicated that the columns and values were imbalanced.

I reviewed the structure with Lexi to make sure the names were right and that I didn't miss anything.

What branch is your code on? Did you git push?

It's on the main right now. I was trying to lay the groundwork in Main before I started trying to branch and develop the views and features.

When was the last time you took a break?

I first encountered this error on Saturday and put it down. I worked some more on it Sunday, but I wasn't able to fix it. I took a break from programming during Justice's lecture. (I'm also taking one right now, and will be back at it after lunch.) I'm debating working on other components after lunch and letting the database marinate, but I'm having issues switching gears even after a break.