json_to_prolog help

Daniel Elliott <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAD=Wj+aPUVnssQSLwV2dunKnfOG0DbQf72Tvnd54_n1_r6Ta2g@mail.gmail.com>
Hello,

I am having some difficulties with the following MWE.  I'm new to
Prolog and this is a small part of a prototype which will, hopefully,
make Prolog a significant part of our production system!  I am
uncertain if my approach is fundamentally flawed (not using the
library correctly), if there is a error, or if I am running up on a
limitation of the JSON support.  I am using pl-6.2.6 which I
downloaded and built.

Here, I am working on code to parse JSON.  The problem is that, in my
example, it does not return a reading record but a json record (may
not be the proper terminology).

:- use_module(library(http/json)).
:- use_module(library(http/json_convert)).
:- json_object
datum(raw:integer, eng:float).
:- json_object
reading_error(sensor_id:integer, rply_code:integer).
:- json_object
reading_datum(sensor_id:integer, data:datum/2).
:- json_object
reading(passwd:integer, datetime:integer, data:list(reading_datum/2)).

Here is the result of two illustrative queries:

?- prolog_to_json(reading(1234,41234,[reading_datum(1,datum(2,3.3))]),JSON_Obj),
format(user_output, '~w', JSON_Obj).
json([passwd=1234,datetime=41234,data=[json([sensor_id=1,data=json([raw=2,eng=3.3])])]])

?- json_to_prolog(json([passwd=1234,datetime=41234,data=[json([sensor_id=1,data=json([raw=2,eng=3.3])])]]),PRLG_Obj).
PRLG_Obj = json([passwd=1234, datetime=41234, data=[reading_datum(1,
datum(2, 3.3))]]).

I want PRLG_Obj to be reading(...), not json(....).

Any help over this hump would be greatly appreciated.  Thank you in advance.

- dan elliott
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.