Accessing a Nested Json and Mapping to Frontend - javascript

I am pulling through an API request which is a nested response. Please see the following response example:
"results": [
{
"company": {
"display_name": "HAYS",
"__CLASS__": "Adzuna::API::Response::Company"
},
"id": "3057817031",
"category": {
"tag": "admin-jobs",
"label": "Admin Jobs",
"__CLASS__": "Adzuna::API::Response::Category"
},
"description": "3 Month Contract available| $30-$33 per hour Super |Full-Time Office Hours based in South Melbourne Your new company An excellent opportunity has become available for a Data Analyst / Administrator to join this manufacturing organisation in their South Melbourne office. Your new role Daily financial reporting (Excel VLookups / Pivot Tables) Organising customer presentations on PowerPoint General Administration Data Analysis duties Tracking back orders within the warehouse Financial duties (bu…",
"salary_is_predicted": "0",
"redirect_url": "https://www.adzuna.com.au/land/ad/3057817031?se=pH90OV3i7BGryyzFGu5MPQ&utm_medium=api&utm_source=627be40a&v=FEB87A947F7D884DC5FF3AF7949D809733A0AA43",
"title": "Data Analyst / Administrator",
"__CLASS__": "Adzuna::API::Response::Job",
"location": {
"display_name": "Melbourne CBD, Melbourne",
"area": [
"Australia",
"Victoria",
"Melbourne Region",
"Melbourne",
"Melbourne CBD"
],
"__CLASS__": "Adzuna::API::Response::Location"
},
"contract_time": "full_time",
"created": "2022-04-16T17:33:31Z",
"adref": "eyJhbGciOiJIUzI1NiJ9.eyJzIjoicEg5ME9WM2k3QkdyeXl6Rkd1NU1QUSIsImkiOiIzMDU3ODE3MDMxIn0.94BaxIfPNOv0QowtSPt1IdwSX0XgU1GtZ9O6MohICTg"
}
The following above indicates 1 singular post in a list.
I have linked this to a fetchJobs operation called 'jobs', and if I do a console.log(jobs.results), I received an array of 10 items, assorted from 0,1,2,3 -> onward to 10.
This as discussed, is the 10 jobs. https://gyazo.com/1bc435e7784efe427a2995150fd54e16
As such, I would like to access a key, any honestly to figure out how to do it, and map it to the front end or console.
For example, results.title or even results.location.area, regardless, I can't seem to access this correctly, as when I try console.log(jobs.rs
TypeError: Cannot read properties of undefined (reading 'title')
Please let me know!
My goal is to just map these keys into a div, so if anyone could post an example, please!

You need to fetch the data in your components useEffect hook,
and then map over the data and render your jobs however you like.

Related

How to wrap something in a var if it has multiple single and double quotes?

Trying to wrap schema code in a var but due to it having multiple single and double quotes I just cannot seem to do it.
Is there another way to wrap something in a var and for it to ignore all single and double quotes in it?
{
"#context": "https://schema.org",
"#type": "FAQPage",
"mainEntity": [{
"#type": "Question",
"name": "What is the return policy?",
"acceptedAnswer": {
"#type": "Answer",
"text": "<p>Most unopened items in new condition and returned within <b>90 days</b> will receive a refund or exchange. Some items have a modified return policy noted on the receipt or packing slip. Items that are opened or damaged or do not have a receipt may be denied a refund or exchange. Items purchased online or in-store may be returned to any store.</p><p>Online purchases may be returned via a major parcel carrier. <a href=http://example.com/returns> Click here </a> to initiate a return.</p>"
}
}, {
"#type": "Question",
"name": "How long does it take to process a refund?",
"acceptedAnswer": {
"#type": "Answer",
"text": "We will reimburse you for returned items in the same way you paid for them. For example, any amounts deducted from a gift card will be credited back to a gift card. For returns by mail, once we receive your return, we will process it within 4–5 business days. It may take up to 7 days after we process the return to reflect in your account, depending on your financial institution's processing time."
}
}, {
"#type": "Question",
"name": "What is the policy for late/non-delivery of items ordered online?",
"acceptedAnswer": {
"#type": "Answer",
"text": "<p>Our local teams work diligently to make sure that your order arrives on time, within our normaldelivery hours of 9AM to 8PM in the recipient's time zone. During busy holiday periods like Christmas, Valentine's and Mother's Day, we may extend our delivery hours before 9AM and after 8PM to ensure that all gifts are delivered on time. If for any reason your gift does not arrive on time, our dedicated Customer Service agents will do everything they can to help successfully resolve your issue.</p><p><a href=https://example.com/orders/>Click here</a> to complete the form with your order-related question(s).</p>"
}
}, {
"#type": "Question",
"name": "When will my credit card be charged?",
"acceptedAnswer": {
"#type": "Answer",
"text": "We'll attempt to securely charge your credit card at the point of purchase online. If there's a problem, you'll be notified on the spot and prompted to use another card. Once we receive verification of sufficient funds, your payment will be completed and transferred securely to us. Your account will be charged in 24 to 48 hours."
}
}, {
"#type": "Question",
"name": "Will I be charged sales tax for online orders?",
"acceptedAnswer": {
"#type": "Answer",
"text":"Local and State sales tax will be collected if your recipient's mailing address is in: <ul><li>Arizona</li><li>California</li><li>Colorado</li></ul>"}
}]
}
Solved using Json Parse
const obj = JSON.parse('{"name":"John", "age":30, "city":"New York"}');

How to get data from an endpoint API in realtime

I would like to get the live results from an Api endpoint preferably using javascript, nodejs. I am looking for more like a technique or idea how to handle this.
Api response looks as following:
[
{
"id": 6,
"team1": {
"name": "Home Team",
"goals": 2
},
"team2": {
"name": "Away Team",
"goals": 1
},
"starting": "2018-09-14T15:30:00Z"
}
]
Probably one way I can think of doing is making a new request every second and get up to date. So each time a team scores this api changes so I get the latest score goal results.
What is the best way I can handle this without overwhelming the resources of the server or probably not get banned from the API Endpoint if I am doing too many requests.

NOAA API Integration

Having trouble getting NOAA API to give the results I want. I have found the data that I would like to use but I cannot get the API to find it. I want to be able to search the records for the average first frost date based on zipcode. The data should be in the NORMAL_ANN dataset. When I use "https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=NORMAL_ANN"; I get a bad request error.
Any ideas on what am I doing wrong? I can get the API to return objects when I use https://www.ncdc.noaa.gov/cdo-web/api/v2/datasets (and I confirmed that NORMAL_ANN is a valid dataset).
Thanks
Ok I found the answer. For 50% probability of first occurence of 28F, the below query is able to fetch a result
https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=NORMAL_ANN&datatypeid=ANN-TMIN-PRBFST-T28FP50&startdate=2010-01-01&enddate=2010-01-01&&stationid=GHCND:USC00047821
The same data can be obtained from their UI tool here
https://www.ncdc.noaa.gov/cdo-web/datasets/NORMAL_ANN/stations/GHCND:USC00047821/detail
The rest query returns result like this:
{
"metadata": {
"resultset": {
"offset": 1,
"count": 1,
"limit": 25
}
},
"results": [
{
"date": "2010-01-01T00:00:00",
"datatype": "ANN-TMIN-PRBFST-T28FP50",
"station": "GHCND:USC00047821",
"attributes": "S",
"value": 361
}
]
}
How to interpret? Value 361 implies 361st day from the start of calendar year which would be 12/27. This confirms with the actual data. To view the actual data, click on "view data" for the station(I used San Jose, CA).

Need to pull Graph API JSON and successively narrow my results

Need to pull from the end point "fb_page_categories" which returns an array of all categories a page could fall under. Which looks like so:
GET graph.facebook.com
/fb_page_categories?
This returns something like so:
{
"data": [
{
"name": "Interest",
"fb_page_categories": [
{
"name": "Literary Arts",
"id": "856055631167537"
},
{
"name": "Performance Art",
"id": "756092301147942"
},
{
"name": "Performing Arts",
"id": "1758092431143387"
},
I then need to pull all of the results of certain specific "categories" that querying said end point returned, and finally filter those categories by proximity to current location. I'm new to java and have no idea where to even begin, or what that code would look like. Any advice, articles, Stack questions, Git projects, etc that can point me in the correct direction would be greatly appreciated. Thanks!
Facebook’s own Graph search for places can do this in a fashion. On Facebook your current location is implicit with being logged in.
First you should be aware that the list of page categories you referenced don’t all allow location. Only categories within the business and organization trees do so. (Facebook refers to this organization as a category taxonomy.)
For example, the ID for Restaurant is currently 273819889375819. So the search result for restaurants nearby would be found at this link.
Graph query for places on Facebook has many other modifiers and it appears there has been continuing development of this feature. After a significant splash a few years ago it appears they have stepped back from fully documenting its use.

Get SoundCloud Artist Page? (Round 2)

I'm still trying to write a function in JavaScript where the user can type in an artist, and it will return a link to that artist's SoundCloud page.
For example,
/artist beyonce --> https://soundcloud.com/beyoncemusic
But the SoundCloud URLS don't all act the same. For example,
/artist dave matthews band --> https://soundcloud.com/dave-matthews-band.
For this reason, I can't simply just output scLink/artistName because they all have different URLs. I'm using Node.js, so I looked through a lot of npm packages, but couldn't figure out how to use any for this purpose. Perhaps Soundclouder will work somehow (though I couldn't figure it out myself). Does anyone know how I could write a command like this?
You are using the SoundCloud API, right?
A simple HTTP request to the right API should return the data you want. For example:
http://api.soundcloud.com/users.json?q=beyonce
[
{
"id": 4293843,
"kind": "user",
"permalink": "beyoncemusic",
"username": "Beyoncé",
"uri": "http://api.soundcloud.com/users/4293843",
"permalink_url": "http://soundcloud.com/beyoncemusic",
"avatar_url": "http://i1.sndcdn.com/avatars-000036935308-a2acxy-large.jpg?435a760",
"country": "United States",
"full_name": "Beyoncé",
"description": "",
"city": "New York",
"discogs_name": null,
"myspace_name": "beyonce",
"website": "http://www.beyonceonline.com",
"website_title": "",
"online": false,
"track_count": 33,
"playlist_count": 2,
"plan": "Pro Plus",
"public_favorites_count": 0,
"followers_count": 478783,
"followings_count": 0,
"subscriptions": [
{
"product": {
"id": "creator-pro-unlimited",
"name": "Pro Unlimited"
}
}
]
},
...
]
...so you could just do results[0].permalink_url.
You can use the request module to make the HTTP request manually, or use soundclouder to handle SoundCloud API's authentication details.
Most of the above does not apply if you want to make the actual requests from a browser. (The question is tagged node.js, but it sounds like you want to do this from a web page.)
If you're doing this from a webpage, use the SoundCloud JS SDK. The data you get back will look like the example above.
I don't think you'd be able to get an exact match reliably. Your best bet would be to search for users with the string you are looking for - example: "beyonce" and then to show the results and let them pick the correct link. You may be able to filter out likely results with follower count (high follower count) or something after you've pulled the initial list from soundcloud.
Search code:
users = SC.get('/users', { q: 'beyonce' });
Then iterate over users and display the permalink url. Hope this helps.

Categories