JSON encoder and decoder

Author(s): Jose F. Morales.

This module defines a term representation for JSON (JavaScript Object Notation), as well as encoders and decoders.

This is an alpha version of the module. Use with care. Both the interface and implementation may change in the future.

Usage and interface

Documentation on exports

REGTYPE

Usage:

A JSON object.

json(json(Attrs)) :-
        json_attrs(Attrs).

    REGTYPE

    Usage:

    Attributes (pairs of key/value) of a JSON object.

    json_attrs([]).
    json_attrs([X|Xs]) :-
            json_attr(X),
            json_attrs(Xs).
    

      REGTYPE
      A regular type, defined as follows:
      json_attr(Id=Val) :-
              atm(Id),
              json_val(Val).
      

      REGTYPE
      A regular type, defined as follows:
      json_val(string(X)) :-
              string(X).
      json_val(X) :-
              number(X).
      json_val(X) :-
              json(X).
      json_val(X) :-
              json_list(X).
      json_val(true).
      json_val(false).
      json_val(null).
      

      REGTYPE

      Usage:

      A list of JSON elements

        PREDICATE

        Usage:json_to_string(Term,String)

        Encode a JSON Term as a character list.

        • Call and exit should be compatible with:
          (json:json/1)A JSON object.
          json(json(Attrs)) :-
                  json_attrs(Attrs).
          

          (basic_props:string/1)String is a string (a list of character codes).
        • The following properties should hold at call time:
          (term_typing:nonvar/1)Term is currently a term which is not a free variable.

        PREDICATE

        Usage:string_to_json(String,Term)

        Decode a character list as a JSON Term.

        • Call and exit should be compatible with:
          (basic_props:string/1)String is a string (a list of character codes).
          (json:json/1)A JSON object.
          json(json(Attrs)) :-
                  json_attrs(Attrs).
          
        • The following properties should hold at call time:
          (term_typing:nonvar/1)String is currently a term which is not a free variable.

        Known bugs and planned improvements