[ library(json) | Reference Manual | Alphabetic Index ]
json_read(+Stream, -JsonTerm, +Options)
Read a JSON element from a stream
- Stream
- Input stream
- JsonTerm
- Term describing JSON object read
- Options
- List of options
Description
    Read a JSON element.  In the resulting data structure, JSON elements are
    represented as follows:
    
    - object
- Structure with functor {}/1 whose single argument is a list of
        Name:Value terms, where Name is a string and Value a JSON element,
        e.g. {["a":123,"b":[4,5]]}, or the empty object{}.
- array
- A list whose elements are JSON elements, e.g. [1,{"a":true}]
- string
- A string
- number
- An integer or float
- true
- the atom true
- false
- the atom false
- null
- the atom null
Options is a list that can contain
    - names_as_atoms
- return object key names as atoms instead of strings
Examples
    ?- json_read(input, JsonTerm, []).
     {
       "foo":123,
       "bar":["hello",3,4.5],
       "baz":true,
       "zut":null
     }
     
    JsonTerm = {["foo":123, "bar":["hello",3,4.5], "baz":true, "zut":null]}
    Yes (0.00s cpu)
    ?- json_read(input, JsonTerm, [names_as_atoms]).
     {
       "foo":123,
       "bar":"hello",
       "baz":true
     }
     
    JsonTerm = {[foo:123, bar:"hello", baz:true]}
    Yes (0.00s cpu)
    ?- json_read(input, JsonTerm, []).
     foobar
     syntax error: invalid JSON syntax in json_read / 3
    Abort
See Also
json_write / 3