Did you know ... | Search Documentation: |
Pack djson -- prolog/djson.pl |
Term = { name: Name, occupation: Job }
json_term/2 considers it acceptable for Json to have extraneous fields that are not present in Term. This allows one to pattern match against a Json document without having to specify every imagineable key.
When dealing repeatedly with the same terms and JSON structures, it's most convenient to declare additional clauses for json//1.
For example,
:- multifile djson:json//1. djson:json(person(Name,Age)) --> json({ name: Name, age: Age }).
?- is_like_json({ hi: world }). true. ?- is_like_json([ a, b, 73 ]). true. ?- is_like_json(foo(_,_)). false.