Using JSON with SWI-Prolog

While my use case is not the exact same as yours, we do have touch points on

  1. The format external to Prolog is JSON.
  2. The internal format does not have to be JSON.

SWI-Prolog internal representation

The internal representations that I need is currently facts in the Prolog database, see: Convert facts to GraphViz dot file using DCGs.

The SWI-Prolog library(http/json) does this with the internal representation being a dictionary and this is a reliable conversion. So if you are open to the format used with SWI-Prolog then using a dictionary, these predicates are handy.

AFAIK CapelliC uses Unweighted Graphs, see: library(ugraphs)


Conversion

library(http/json) comes with predicates that convert to and from SWI-Prolog dictionaries.

I am using DCGs.

AFAIK CapelliC uses Quasi Quotation, see library(quasi_quotations)

Using a functional approach with library(yall) is also a possibility but not one I plan to explore.


While I do like the reliability and ease of using library(http/json), for my specific use case that means I have to deal with dictionaries along the way. Since most of what I plan to generate will be boilerplate code the DCG still seems reasonable.