generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧠 Logic: 🧱 json_prolog
, add predicate to convert json to prolog terms
#348
Comments
bdeneux
changed the title
[DRAFT] 🧠 Logic: add predicate to convert json to prolog terms
[DRAFT] 🧠 Logic: 🧱 Apr 26, 2023
json_prolog
add predicate to convert json to prolog terms
bdeneux
changed the title
[DRAFT] 🧠 Logic: 🧱
[DRAFT] 🧠 Logic: 🧱 Apr 26, 2023
json_prolog
add predicate to convert json to prolog termsjson_prolog
, add predicate to convert json to prolog terms
This is excellent! Thanks @bdeneux 🥇 I think this is functionally speaking complete and pretty suitable. We may just need to mention the edge case of a simple string being a valid JSON. |
That's brilliant @bdeneux 🤩! |
bdeneux
changed the title
[DRAFT] 🧠 Logic: 🧱
🧠 Logic: 🧱 Apr 28, 2023
json_prolog
, add predicate to convert json to prolog termsjson_prolog
, add predicate to convert json to prolog terms
Main specification updated since implementation of the json empty array fix : #398. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
📝 Purpose
In the
logic
module, we will need a set of new predicates to handle json conversion between json string to prolog term and vice versa.🧪 Expected behavior
Where
Json
is the string representation of the jsonTerm
is an Atom that would be unified by the JSON representation as Prolog terms.In addition, when passing Json and Term, this predicate return true if both result match.
The canonical representation for Term is:
Mapped to a term
json(Attributes)
, whereAttributes
is a list of all JSON attributes mapped to a pair term-(Attribute, Value)
, whereAttribute
is an atom created from the JSON string andValue
is the JSON value.Result:
@
functor :@([])
. See #398 for more details.Result:
"foo"
Result:
1
Result:
Constant
true
andfalse
Atom
@(true)
and@(false)
true
Result:
Constant
null
Atom
@(null)
null
Result:
Note: converting a simple string, boolean, integer or null value are valid json and will be unified to an simple atom.
To ensure determinism on the chain, the result of the JSON conversion is canonicalized by sorting the JSON name attribute. Same behavior for the json representation on prolog :
{"b": "a", "a":"c"}
=>json([a-c,b-a])
andjson([b-a,a-c])
=>{"a":"c", "b":"a"}
.🎯 Example
Given the following JSON
✅ Acceptance Criteria
🔗 References and linked predicate
The text was updated successfully, but these errors were encountered: