SWI-Prolog JSON library
Jan Wielemaker
SWI-Prolog Solutions b.v.
The Netherlands
E-mail: jan@swi-prolog.org
Abstract
This package reads and writes JSON documents from and to SWI-Prolog streams, files and strings.

Table of Contents

1 Supporting JSON
1.1 library(json): Reading and writing JSON serialization
1.2 library(json_convert): Convert between JSON terms and Prolog application terms
1.3 library(http/http_json): HTTP JSON Plugin module

1 Supporting JSON

From http://json.org, " JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language."

Although JSON is nowadays used a lot outside the context of web applications, SWI-Prolog's support for JSON started life as part of the HTTP package. SWI-Prolog supports two Prolog representations for JSON terms. The first and oldest map JSON objects to a term json(PropertyList) and use the @ functor to disambiguate e.g. null from the string "null", leading to @(null). As of SWI-Prolog version 7, JSON objects may be represented using dict objects and JSON strings using Prolog strings. Predicates following this convention are suffixed with _dict, e.g. json_read_dict/2. For example, given the JSON document

{ "name": "Bob", "children": ["Mary", "John"], "age":42, "married": true }

we get either (using json_read/2):

json([name='Bob', children=['Mary', 'John'], age=42, married= @(true)]).

or (using json_read_dict/2):

_{age:42, children:["Mary", "John"], married:true, name:"Bob"}

The SWI-Prolog JSON interface consists of three libraries:

Index

?
atom_json_dict/3
atom_json_term/3
current_json_object/3
http:post_data_hook/3
http_client:http_convert_data/4
http_read_json/2
http_read_json/3
http_read_json_dict/2
http_read_json_dict/3
is_json_content_type/1
is_json_term/1
is_json_term/2
json/4
json_dict_pairs/2
json_object/1
json_read/2
json_read/3
json_read_dict/2
json_read_dict/3
json_to_prolog/2
json_type/1
json_write/2
json_write/3
json_write_dict/2
json_write_dict/3
json_write_hook/4
prolog_bool_to_json/2
prolog_to_json/2
reply_json/1
reply_json/2
reply_json_dict/1
reply_json_dict/2