[Ocs] JSON spec

Mohd Izhar Firdaus Ismail kagesenshi.87 at gmail.com
Thu Feb 9 10:06:37 PST 2012


On Fri, Feb 10, 2012 at 1:14 AM, Laszlo Papp <lpapp at kde.org> wrote:
>> as I understood there from roughly going through the php code.
>>
>> * subtags of <meta> becomes top level,
>
> <snip>
>
> I cannot comment on the reference php implementation (though some of
> the notes, what you have just said, sound strange :/), nor on your
> python project because I am very much a newbie in those areas. ;)

what i meant was:

<ocs>
   <meta>
       <status>ok</status>
       <message>success</message>
   </meta>
   <data>
       <person details="summary">
           <personid>user</personid>
       </person>
       <person details="summary">
            <personid>user2</personid>
       </person>
   </data>
</ocs>

turns to

{
  'status': 'ok',
  'message': 'success',
  'data': [{
     'personid': 'user'
  },{
     'personid': 'user2'
  }]
}

at least thats what i understood from the php code. I didnt try to run it.

currently i use this format:

{'ocs' : {
  'meta': {
    'status':'ok',
    'message': 'success'
    },
    'data': {
      'person': [{
         'personid: 'user'
      }, {
         'personid': 'user2'
      }]
    }
  }
}

which i can transform to xml directly using the python xmldict
library. however, it has lack of support for xml attribute for
dict_to_xml conversion ..

>
> But:
>
> 1) I think we could standardize the json output with a concrete
> description and example in each case next to the XML output in a
> similar way as this:
> http://www.thomasfrank.se/xml_to_json.html

looks similar to xmldict's xml_to_dict converter ..

>
> It is important to preserve the same parent and child node relations
> in xml, also in the json output, in my opinion. I can write a mockup
> into the draft according to the above conversion, but I would like to
> know first: what others think. Opinions ?

my concern is xml attribute representation in the json. if you see the
conversion format, it changes <cat name="matilda"/> to {'cat':
{'name': 'matilda'}}, which, if we try to convert back to xml, turns
to <cat><name>matilda</name></cat>.

and things might get tricky if theres <person
details="summary"><details>user description</details></person> .. how
would that work?.  of course if xml attribute is not used altogether,
things get simpler and easier to use for such conversion.

programming wise, to me at least, its easier and faster to deal with
json than xml as its very close to native types especially in python
(dictionary), ruby (hash), php (key-value array), javascript ..

> 2) It is nice to see you have been trying to use OCS, and thanks for
> that. :) I am unsure whether or not there are already python reference
> implementations out there (at least not mentioned here:
> http://www.socialdesktop.org/library/) on the server side, but if not:
> you could probably bear in mind the separation between your
> "boilerplate" OCS specification implementation and the real server
> application code so that the "boilerplate" code could be decoupled
> later into a reference library.

not exactly sure if its really worth it to separate it out at least in
my app, as i simply construct the dictionary directly when querying
the table.

nonetheless, will see what i can do.

>
> 3) I can extend the Qt based client library with JSON output parsing
> to get it work properly after we have the precise outputs in place. I
> believe there are already re-usable parsers in the Qt world.
>
> Thank you for your interest again. :)
>
> Best Regards,
> Laszlo Papp



-- 
Mohd Izhar Firdaus Bin Ismail / KageSenshi
Inigo Consulting (FOSS/Plone Development, Training & Services)
http://www.inigo-tech.com
Fedora Malaysia Contributor & Ambassador
http://blog.kagesenshi.org
92C2 B295 B40B B3DC 6866  5011 5BD2 584A 8A5D 7331


More information about the Ocs mailing list