Re: Nested Prolog term to JSON object conversion

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi Wouter,

On 07/13/2013 08:47 PM, Wouter Beek wrote:
> Hi all,
>
> Has somebody been able to convert nested Prolog terms into JSON objects
> using json_object/1 declarations?
>
> ~~~
> :- module(test, [test/0]).
>
> :- use_module(library(http/json_convert)).
>
> :- json_object circle(coord:atom) + [type=circle].
> :- json_object coord(x:float, y:float) + [type=coord].
>
> test:-
>    prolog_to_json(circle(coord(3.4,4.3)), JSON_Object),
>    format(user_output, '~w', JSON_Object).
> ~~~
>
> At some points in the trace, the contents of coord/1 are assumed to be
> atomic :-(

That makes sense if you state circle(coord:atom).  If you change this 
into circle(coord:coord/2), you get:

3 ?- test.
json([coord=json([x=3.4,y=4.3,type=coord]),type=circle])

	Cheers --- Jan

P.s.	Note that 6.3.19 has several additions and fixes for the
	json_convert.pl library.


>
> ---
> Cheers!,
> Wouter.
>
> E-mail: [email protected]
> WWW: www.wouterbeek.com
> Tel.: 0647674624
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
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.