Convert dictionary to json dictionary?

Based on this minimal .pl-file:

:-op(800, fx, ¬).
:-op(801, xfy, ∧).
:-op(802, xfy, ∨).
:-op(803, xfy, →).
:-op(804, xfy, ↔).

I am able to define dictionaries of this form:

A = proof{1: ¬q, 2:p→q, 3: ¬ (¬p), 4: ¬p, 5:[edge(¬p, ¬p∧ ¬ (¬p)), edge(¬ (¬p), ¬p∧ ¬ (¬p)), rule('∧I')], 6:[edge(¬p, p), edge(¬p∧ ¬ (¬p), p), rule('¬E')], 7:[edge(p, q), edge(p→q, q), rule('→E')], 8:[edge(q, q∧ ¬q), edge(¬q, q∧ ¬q), rule('∧I')], 9:[edge(¬ (¬p), ¬p), edge(q∧ ¬q, ¬p), rule('¬E')]}.

Is their a predicate to convert this dictionary in the following string representation (background, to handle with it into other languages like python):

B = proof{1:'p→q',2: '¬q',3: '¬ (¬p)',4: '¬p',5:['edge(¬p,¬p∧ ¬ (¬p))','edge(¬ (¬p),¬p∧ ¬ (¬p))','rule("∧I")'],6:['edge(¬p,p)','edge(¬p∧ ¬ (¬p),p)','rule("¬E")'],7:['edge(p,q)','edge(p→q,q)','rule("→E")'],8:['edge(q,q∧ ¬q)','edge(¬q,q∧ ¬q)','rule("∧I")'],9:['edge(¬ (¬p),¬p)','edge(q∧ ¬q,¬p)','rule("¬E")']}.

or

B ={1:'p→q',2: '¬q',3: '¬ (¬p)',4: '¬p',5:['edge(¬p,¬p∧ ¬ (¬p))','edge(¬ (¬p),¬p∧ ¬ (¬p))','rule("∧I")'],6:['edge(¬p,p)','edge(¬p∧ ¬ (¬p),p)','rule("¬E")'],7:['edge(p,q)','edge(p→q,q)','rule("→E")'],8:['edge(q,q∧ ¬q)','edge(¬q,q∧ ¬q)','rule("∧I")'],9:['edge(¬ (¬p),¬p)','edge(q∧ ¬q,¬p)','rule("¬E")']}.

' by default is an atom not a string, :slightly_smiling_face:

e.g.

?- atom('p→q').
true.

?- string('p→q').
false.

Strings are created with " by default.

e.g.

?- atom("p→q").
false.

?- string("p→q").
true.

Some of these defaults can be changed with Prolog flags but you did not note the use of such so in reading your question I would take that you are using the defaults.


EDIT

In the title you note json dictionary, which may lead one to think there is a SWI-Prolog dictionary just for json. AFAIK there is none. JSON can be converted to/from an SWI-Prolog dictionary most of the time and with caveats. See: Json_dict/2 - Helpful for learning how to use JSON with SWI-Prolog dict

Also of value: Sites for testing JSON

1 Like

Thanks for the hint.