Back to articles
Reddit Has a Secret JSON API — Just Add .json to Any URL

Reddit Has a Secret JSON API — Just Add .json to Any URL

via Dev.to WebdevАлексей Спинов

Did you know you can get structured JSON from Reddit without any API key, OAuth tokens, or rate limit headaches? The Trick Append .json to any Reddit URL: https://www.reddit.com/r/webdev.json https://www.reddit.com/r/python/top.json?t=week&limit=25 https://www.reddit.com/r/datascience/search.json?q=web+scraping&sort=new https://www.reddit.com/user/spez/about.json Code Example async function getRedditPosts ( subreddit , sort = " hot " , limit = 25 ) { const url = `https://www.reddit.com/r/ ${ subreddit } / ${ sort } .json?limit= ${ limit } ` ; const res = await fetch ( url , { headers : { " User-Agent " : " MyApp/1.0 " } }); const data = await res . json (); return data . data . children . map ( post => ({ title : post . data . title , author : post . data . author , score : post . data . score , comments : post . data . num_comments , url : post . data . url , created : new Date ( post . data . created_utc * 1000 ). toISOString () })); } const posts = await getRedditPosts ( " startup "

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
6 views

Related Articles