Yahoo weather-api response as json - json

I am using yahoo weather api to get weather information
This is returning an xml output.
I want to get it in JSON format. How can i get this as JSON?

I would suggest using YQL and requesting JSON output. The link you referenced is Yahoo's weather RSS feed.
http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json

http://weather.yahooapis.com/forecastjson?w=2502265
Just replace forecastrss by forecastjson in the URL.
I see one drawback: No weather-code is returned for the forecast.
Update 2014-06: This used to work, but seems to be gone since 2012-10 (see also https://developer.yahoo.com/forum/YQL/-/1349591762366-e0f8ad94-f599-49fe-bddb-fe3cd0180dea)

As per the documentation at http://weather.yahooapis.com/forecastrss, the rss response is xml.
The Weather RSS feed is an XML
document that conforms to the RSS 2.0
specification. RSS is an XML document
containing a single channel element
representing the feed, several
elements containing metadata about the
feed itself, and one or more item
elements describing individual items
within the feed.
And so, you won't get the response as JSON

if you are looking for a JSON weather API I have a suggestion for you!
I made a Weather API available on mashape, and they have a ready to use simple PHP SDK.
This api is really simple to use because we use the cool standards that are available nowadays, like JSON and REST, while our competitors still use legacy SOAP/XML systems.
Speaking about the quality of data Metwit (my "company") born as a crowdsourced platform for gathering real-time weather reports from real people. After more then ten thousand users started to using our apps and send a massive amount of reports,
we decided to release those precious reports through our APIs.
We also act as single gateway for multiple, hard to parse, sources of forecasts like NOAA, and we're enhancing them with social data like photos, tweets, etc., that we leverage from existing social networks.
If you like it please give it a try on mashape!

After a few search i found the yahoo weather api is best for me as what i really needed.
To get the weather data from latitude and longitude
In XML (default)
http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="({28.3949},{84.1240})")
In JSON format
http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="({28.3949},{84.1240})")&format=json
Your ouput will be like below
Put your own place latitude and longitude to find your location weather, hopefully this will help.

Related

How to find how many json endpoints an api has

I’m in the middle of making an Express app. It’s just a learning project.
I’m getting some info from an Anime api called jikan.me, it provides info about different Anime series like a picture url and synopsis.
For example one is at https://api.jikan.me/anime/16 .
Now, the jikan api might have a json endpoint at anime/1 but there's nothing at anime/2.
I want to find a list of all the numbers (https://api.jikan.me/anime/[numbers]) that actually contain endpoints.
I've tried simply going to https://api.jikan.me/anime but it returns error: No ID/Path Given.
I'm expecting there is likely no absolute answer to this problem but that I might learn something about server-side code along the way.
Where would I begin to look to find this info?
This is a bit late but, Jikan is an unofficial REST API for MyAnimeList. The IDs are respective to the IDs on MAL. For example; https://myanimelist.net/anime/1 can be parsed through https://api.jikan.moe/anime/1 but the ID 2 does not exist on MAL. It's a 404, hence that error.
To initially get some IDs, you can try the search endpoint.
Furthermore, I'll be releasing REST 2.2 quite soon (this month) which will give you the ability to parse from pages like these and thus you'll get another endpoint that provides a handful of IDs to get their data from.
Source: I'm the developer of Jikan
If it's not in the documentation it's probably information not available to you... a REST api needs to be specifically configured to offer certain endpoints, that number at the end might just be an ID that's searched for in an internal database and there's no way for the application to know if there's gonna be something there; all they can do is return an error message for you to handle as is the case here.

converting json string to texteditor

i am a real noob. The thing is, i dont know where to turn. we, as in myself and my thesis partner are trying to build (theoreticly) a platform which has an own search engine directed only at the databases of wikipedia. Now when you download articles or an article, using the wikipedias api you get a json formatted string, now the question is how do i convert that json code string into just text?
like a plain simple english?
and if you have any suggestions on search algorithms for the search engine that would also be helpfull.
(note) if you can give me an explanation otherwise just give directions on keywords to search for
You would typically use a function to convert that json to object and then take the property that is of interest to you.
pseudo code:
function getTextFromwikiArticleJson(json){
var realobject = JSON.decode(json);
return realobject.content.body;
}
JSON is just (one of) the format(s) used to transfer data over internet. It then needs to be processed (i.e. parsed) in order to extract the information you want.
A wikipedia API call might give you much more information than you actually want (so called meta-data), such as creation date, authors, etc.
You are probably interested in the text of the article, so you need to access the corresponding entry in the JSON.
Try pasting the JSON in an online parser, such as https://jsonformatter.org/json-parser.
Also, read about JSON here: https://en.wikipedia.org/wiki/JSON
Most programming languages have functions to parse JSON data (often via external libraries, such as gson for Java, for example)

Where can I find a pre-populated json file for testing?

I am building an application that can import JSON data, I want to test about 10k entries, and I don't feel like building a JSON string with that many entries.... so does anyone have a location where I could find some generic populated JSON files? (Music Albums / Movie Listings / Animal Kingdom / Census data / Car Models... I'm not horribly picky, I just need some good data to test with.)
This is a site that is in beta that can give you data in JSON, XML or CSV. All lists are customizable. This is a sample call: http://mysafeinfo.com/api/data?list=englishmonarchs&format=json
Documentation here: http://mysafeinfo.com/content/documentation ; See a full list under Datasets on the main menu
There are few websites that have raw data that can be customized to a JSON format. Here is a link for some raw data information Data
Vienna's Open Data website provide various databases. For example, their Tree register
Edit:
The old link is dead. A great place to find test data is Socrata which aggregates government data. There's plenty of data to test with:
https://dev.socrata.com/data/
If you look through the catalogs, there's usually a JSON export option. Here's an example from the National Service for Age Group and volunteering.

Is it possible to parse a Google+ (Google Plus) profile page?

If you view the source of a Google+ profile page, it appears rather complex. It seems most of the data is kept in a huge JSON-like objects. However, they don't seem to be really JSON, since they don't get recognized when I try to decode them. I am hoping the format is more clear to other people here. How would you go about parsing it? It seems it would fairly trivial, if you know where to start.
Here is a sample profile, for example: http://plus.google.com/104560124403688998123
Here's a PHP API I'm working on. It can download and parse the data for a profile page and people's public relationships.
https://github.com/jmstriegel/php.googleplusapi
The JSON piece is a bit mangled. To generate valid JSON, you basically have to remove the first 5 characters that prevent XSRF attacks and then add in all the nulls that have been removed. Here's the code specific to handling parsing the weird Google Plus JSON responses:
https://github.com/jmstriegel/php.googleplusapi/blob/master/lib/GooglePlus/GoogleUtil.php
Call GoogleUtil::FetchGoogleJSON( $url ) and you'll get back a giant array that you can then pull data from. Using this, it should be trivial to make a proxy service to translate stuff into valid json(p) for you to use in your own apps.
I don't have access to Google+ yet, so I'll just answer the general question - that is, how to parse JSON.
JSON is just JavaScript, so parsing it is as simple as evaluating the script. To do this, use the eval() JavaScript function.
var obj = eval('{"JSON":"goes here"}');
Another option is to leverage a console tool. Popular modern browsers pretty much all have them. I recommend Firebug for Firefox in particular.
Using Firefox, log into Google+, then open the Firebug console. You can use the console's dir() command to create a browseable representation of the data. Ex:
console.dir(eval('{"JSON":"goes here"}'));
Sorry I can't be more specific about how to get a handle on Google+'s JSON in particular; without access to the service, this is about the best I can do blind. Good luck!
Thanks to Jason for the excellent php class which reads a profile page into an array.
I've used this class as a base and then parsed it, based upon Russell Beattie's python code from the original appspot rss feed application.
Code here
A few notes:
I use this to merge G+ and WP feeds, hence writing posts into an intermediate array ($items).
I have a convention of creating a pseudo title in Google Plus posts, by emboldening a line and adding two newlines before writing the post. The function getTitle strips this out as a better formatted title in my website and getSummary produces the rest of the post with duplicating the title.
It's made up of a number of parts, an object describing your picasa images, one describing the fields on your profile, one describing your friends.
Most of the long numbers are the internal IDs of people, posts and photos. For instance, my ID is 105249724614922381234. Other than that, it could be parsed if you needed to.

How to get Google Maps Public Transit Directions by HTTP server-side request

I use such urls like:
http://maps.google.com/?saddr=546%206th%20Avenue,%20New%20York,%20NY%2010011%20(Sixth%20Avenue,%20New%20York)&daddr=W%20103rd%20St,%20New%20York,%20NY%20&dirflg=r
But it returns full html page. Does anybody know how to get such info in json or xml or any parsable format?
I need public transit.
You just add &output=json to the end of the url.
I'd like to extend Mathias's answer a little bit.
There's no official Google Transit API at the momemnt. Transits are provided by agencies, and most of Transits are not public. So, Google is not allowed to open them as API.
You may try to consume the "unofficial" data using your link + "&output=json".
However, the result won't be a valid JSON. Instead, that's something, that can be easily converted to a JavaScript object. (The differences are: there is no quotes around property names,
the strings are not properly encoded etc.)
Imagine you got this JavaScript object. However, it won't allow you to easily get the structured route details. Object's properties contain the route points coordinates, but no descriptions. The only place where the descriptions may be found is 'panel' property, which contains a chunk of HTML text (you may find a link to the sample of HTML in my blog post)
So, you'll have to convert this HTML into XML (X-HTML) and then build the parser of this XML to get the essence data of a trip.
Seems like a bit of overkill to me. Having in mind, that "unofficial" API may change in the future, including slight changes in 'panel' HTML structure that will kill your parser.
#MathiasLin, how did you overcome this?
Google Maps Javascript v3 and the Directions Web Service now has this capability as per :
https://googlegeodevelopers.blogspot.in/2012/06/public-transit-routing-and-layer-now.html
Update:
Latest server side API docs:
https://developers.google.com/maps/documentation/directions/get-directions
Re choosing public transport - it seems that it defaults to public transport now (at least when I use it).
Changing the last URL parameter, dirflg=r, into dirflg=w switches the directions to walking mode.
Plus see:
Walking, bicycle and public transport directions with time required in each mode , iPhone
for more detail about the parameters.
Google direction API response is in HTML, JSON format please check https://developers.google.com/maps/documentation/javascript/directions?hl=lv
& section 'The DirectionsResult Object'