Inconstistent formatting of results in JSON

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Inconstistent formatting of results in JSON

Jools Wills
I'm having some problems which are caused by some inconsistent formatting
of results from the API in format JSON. This is making problems for a perl
module I made.

Take this example:

http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Physics&cmsort=timestamp&cmdir=desc&format=jsonfm

results are returned in an array and so are easy to loop through. This is
how most of the results are formatted from the "list" query types.

now take this one:

http://en.wikipedia.org/w/api.php?action=query&list=backlinks&bltitle=Main%20Page&bllimit=5&blfilterredir=redirects&format=jsonfm

the results are not in an array but a hashref of hashrefs with the pageid
being the key (and the page id is also in the hashref too)

Is this a bug, or could this be changed so that the api returns results in
a consistent manner (as with the XML).

Best Regards

Jools


_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: Inconstistent formatting of results in JSON

Roan Kattouw
Jools Smyth schreef:

> I'm having some problems which are caused by some inconsistent formatting
> of results from the API in format JSON. This is making problems for a perl
> module I made.
>
> Take this example:
>
> http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Physics&cmsort=timestamp&cmdir=desc&format=jsonfm
>
> results are returned in an array and so are easy to loop through. This is
> how most of the results are formatted from the "list" query types.
>
> now take this one:
>
> http://en.wikipedia.org/w/api.php?action=query&list=backlinks&bltitle=Main%20Page&bllimit=5&blfilterredir=redirects&format=jsonfm
>
> the results are not in an array but a hashref of hashrefs with the pageid
> being the key (and the page id is also in the hashref too)
>
> Is this a bug, or could this be changed so that the api returns results in
> a consistent manner (as with the XML).
I don't really see the problem here: most languages have some sort of
construct to loop through hashrefs. You're right that there's an
inconsistency, though. I'll investigate which format (list or hashref
with pageid keys) is more common and use that throughout.

Roan Kattouw (Catrope)

_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Reply | Threaded
Open this post in threaded view
|

Re: Inconstistent formatting of results in JSON

Jools Wills
> I don't really see the problem here: most languages have some sort of
> construct to loop through hashrefs. You're right that there's an
> inconsistency, though. I'll investigate which format (list or hashref
> with pageid keys) is more common and use that throughout.

the problem isn't that I am unable to loop through it. the problem is I
provide a perl module for interfacing with the mediawiki api. It has a
helper function for the list query types, which automatically handles
query continues and combines multiple results. the backlinks doesn't work
with it however, and must be processed manually.

Thanks for looking into this. the array format is easier to process which
is used by most of the list calls and doesn't have the repeating of
information too (pageid->pageid).

Best Regards

Jools


_______________________________________________
Mediawiki-api mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api