reply_json error with compound term

81 views
Skip to first unread message

JP Thompson

unread,
Jul 21, 2014, 9:46:43 PM7/21/14
to swi-p...@googlegroups.com
I get an error when I try to send a json reply that includes a compound term:
 
?- reply_json(json(['A'=p(p)])).
Content-type: application/json

{
ERROR: atom_length/2: Type error: `list' expected, found `p(p)'

 Is it possible to make the term p(p) serialize to the string 'p(p)' when using reply_json?
 

Jan Wielemaker

unread,
Jul 22, 2014, 4:15:14 AM7/22/14
to JP Thompson, swi-p...@googlegroups.com
In general, this is a bad idea as if the term you pass is by accident some
valid Prolog representation of a JSON term, you'll get totally unexpected
JSON. It can be practical though, so I've added an option
serialize_unknown(true)
that does this. Use with care. Available in the development git version.

Cheers --- Jan


>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages