Skip to content

Commit

Permalink
docs(logic): describe JSON canonical representation
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Oct 8, 2024
1 parent 61cab94 commit ddf1cea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
17 changes: 13 additions & 4 deletions docs/predicate/json_prolog_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_position: 15

## Description

`json_prolog/2` is a predicate that will unify a JSON string into prolog terms and vice versa.
`json_prolog/2` is a predicate that unifies a JSON into a prolog term and vice versa.

The signature is as follows:

Expand All @@ -17,10 +17,19 @@ json_prolog(?Json, ?Term) is det

Where:

- Json is the string representation of the json
- Term is an Atom that would be unified by the JSON representation as Prolog terms.
- Json is the textual representation of the JSON, as either an atom, a list of character codes, or a list of characters.
- Term is the Prolog term that represents the JSON structure.

In addition, when passing Json and Term, this predicate return true if both result match.
## JSON canonical representation

The canonical representation for Term is:

- A JSON object is mapped to a Prolog term json\(NameValueList\), where NameValueList is a list of Name\-Value pairs. Name is an atom created from the JSON string.
- A JSON array is mapped to a Prolog list of JSON values.
- A JSON string is mapped to a Prolog atom.
- A JSON number is mapped to a Prolog number.
- The JSON constants true and false are mapped to @\(true\) and @\(false\).
- The JSON constant null is mapped to the Prolog term @\(null\).

## Examples

Expand Down
15 changes: 13 additions & 2 deletions x/logic/predicate/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ import (
// json_prolog(?Json, ?Term) is det
//
// Where:
// - Json is the textual representation of the json, as an atom, a list of character codes, or list of characters.
// - Term is a term that represents the JSON in the prolog world.
// - Json is the textual representation of the JSON, as either an atom, a list of character codes, or a list of characters.
// - Term is the Prolog term that represents the JSON structure.
//
// # JSON canonical representation
//
// The canonical representation for Term is:
// - A JSON object is mapped to a Prolog term json(NameValueList), where NameValueList is a list of Name-Value pairs.
// Name is an atom created from the JSON string.
// - A JSON array is mapped to a Prolog list of JSON values.
// - A JSON string is mapped to a Prolog atom.
// - A JSON number is mapped to a Prolog number.
// - The JSON constants true and false are mapped to @(true) and @(false).
// - The JSON constant null is mapped to the Prolog term @(null).
//
// # Examples:
//
Expand Down

0 comments on commit ddf1cea

Please sign in to comment.