JSON "RAW" (simplified) Output...

Hey,

I was testing the “JSON” output option added recently, and noticed that it includes formatting and such.

Personally, when I think of an API, I think of raw output data.

What I’d like is the ability to turn off the formatting, so that the output is raw in nature.

Ex. (the following is represented as an array for demonstration purposes)

$output = array(“command” => “list-domains”,“status” => “success”,“output” => array(array(“name” => “Domain”,“value” => “mydomain.com”),array(“name” => “Domain”,“value” => “myotherdomain.com”)));

*** the example does not include all available data for command ***

As a app developer, this would allow me more flexibility as I could decode the JSON text into a clean object and/or array using the programming language of choice, then display the content however I wanted to. All this without having to do more unneeded parsing, and/or striping of content. In theory this should also make creating the API output a bit more faster as you get rid of unneeded tags and such.

Just a thought.


Peter

It sounds like you may need the “multiline” parameter to be set as well, which switches to a more parsable and JSON-friendly output format. What is the API URL you are calling currently, and what output are you getting?

Jaimie,

The multiline option does not make it any more parsable in my opinion. The output still includes lots of extra stuff which isn’t useful.

*** It only slightly makes it more parsable by “status”, “output”, and “command” in separate arrays when parsed using “json_decode” in PHP5. The “output” is still pretty messy considering it’s one big blob of text. ***

The ideal way to parse an API in my opinion is to remove all formatting related stuff from the output as this is the job of the client side scripting, not the server outputing the API response.

What I am proposing long term is a rewrite of how the actual API outputs responses, as by going to a more globally friendly output format, it would make the API more flexible, would require less striping of unneeded garbage code, and in theory faster since the API would not be creating all this code before outputing it.

If you’d like, I’d be happy to draw up output schemas for each command as I feel they should be done and contribute whatever I can to help make things easier on you guys.

Don’t get me wrong, I love Virtualmin, just the API has always seemed a bit more daunting to me in terms of usability given its current state.

– Peter

I’d be interested to see what kind of output you are looking for, in order to make it more parsable.

Also, what is the exact API URL you are calling? You shouldn’t be seeing a big blob of output text … it is supposed to be converted into a JSON structure which your code can then walk to get the needed information.

Jamie,

Sorry for the long delay in getting back to you on this particular thread.

I had temporarily put the idea on the back burner so to speak.

Anyways, when I do:

http://:/virtual-server/remote.cgi?program=list-domains&multiline&json=1

Then I use “json_decode” in PHP5, I get back an object including three key/value pairs.

“status”, “output”, and “command”.

status: this says success which is fine.
output: this has a ton of information in both key/value and just value format split by “\n” and “:” respectively.

ex:

mydomain.com


ID: 1234567890


Type: Top-level server


Plan: My Plan Name

etc…

comand: this just shows me the command I ran, in this case being “list-domains” which is fine.

The “output” value is what I feel could use some serious work in order to make it more easier to work with.

What I’d like to see is a multi-dimensional array upon decoding from JSON.

One that shows a consistent key/value pair for each entry, and one that is easily parsed.

ex.

[0]


   [domain] => mydomain.com


   [id] => 1234567890


   [type] => Top-level server


   [plan] => My Plan Name

[1]


   [domain] => myotherdomain.com


   [id] => 2345678901


   [type] => Top-level server


   [plan] => My Plan Name

etc.

I believe this would make things easier to parse, as we’d just be able to iterate through the top level array, evaluate weather a specific key was present, and display accordingly.

This ofcourse combined with the filtering options like “user”, “domain”, etc (which I know exists) would be paramount.

Thanks in advance for your consideration and/or suggestions!

I see the issue … in the URL, you need to use multiline= instead of just multiline . Then you’ll get the output you want …

wicked!

you da man!

ha ha! such a simple little thing. LOLz

thanks a bunch.