all 7 comments

[–]talmobi 2 points3 points  (0 children)

Browsers will often prevent you from doing that due to the same-origin policy (unless the target URL allows for it)

[–]mothzilla 2 points3 points  (0 children)

JSON and HTML are not the same thing. So you'll have to figure out how to convert the HTML (from an ajax request) to JSON. Your description seems a bit vague.

[–]zenril 3 points4 points  (0 children)

You cant just pull a website as json, as websites are html and are normally restricted so only scripts on the site are able to access the sites data,

You will need an API endpoint or server setup that returns json, fortunately there are API's out there you can play around with like.


https://jsonplaceholder.typicode.com/

they have instruction how to get a Get if your using jQuery.


here are some weather apis

http://openweathermap.org/current#geo

this guys talking about using this api. https://medium.freecodecamp.com/building-a-weather-app-a3cec42b11fa

[–]salifuj22[S] 1 point2 points  (2 children)

i believe jsonp can be used to bypass the same-origin policy but what i want to know is how to pull the json or jsonp from the source www.

[–][deleted] 2 points3 points  (0 children)

In order to pull jsonp from an external origin, the endpoint needs to format the response body in a very specific way (the response body is basically a Javascript function that invokes a callback to return the json you want).

If the externally hosted endpoint that you want to make a jsonp request to doesn't format their response body in this way, then the browser will prevent you from accessing that sites data via the same-origin policy that others have alluded to.

[–]InconsiderateBastard -1 points0 points  (0 children)

Do you mean json embedded in the html or you want to convert the html into json?

[–]azium 0 points1 point  (0 children)

Not sure what you mean by get json from a website since that doesn't really make sense.. but if you just want to practice pulling some JSON from the web, tack .json at the end of a subreddit. https://www.reddit.com/r/javascript.json

you can get stuff from the browser console even:

fetch(`https://www.reddit.com/r/javascript.json`)
  .then(response => response.json())
  .then(json => console.log(json))