reply_json error with compound term

Skip to first unread message

JP Thompson

Jul 21, 2014, 9:46:43 PM7/21/14
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

Jul 22, 2014, 4:15:14 AM7/22/14
to JP Thompson,
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
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
> <>.
> Visit this group at
> For more options, visit
Reply all
Reply to author
0 new messages