Skip to main content

JSON

A record represents a set of attributes and their corresponding values of an artifact. For example, the following record may represent that a person named Tore has the income 100000:

{"name":"Tore", "income":100000}

Other commonly used terms for records are JSON objects, property lists, or dictionaries.

Let's assign the record above to a variable :t:

set :t = {"name":"Tore", "income":100000};
:t
Not connected

To run this code block you must be logged in and your studio instance must be started.

An attribute a in a record r can be accessed using the r[a] notation, for example:

:t["name"]
Not connected

To run this code block you must be logged in and your studio instance must be started.

Functions

geodist(Record x,Record y)->Number

Get the distance in meter between Google Maps locations x and y


geo_coordinate(Record r)->Vector of Number

Convert a Google Maps loction r to a coordinate vector


geo_location(Vector v)->Record

Convert a coordinate vector 'v' on format [lng, lat] into a Google Maps location


json:file_stream(Charstring file)->Stream

Stream of JSON objects in file


json:load(Charstring model,Charstring file)->Charstring

Load exported functions from JSON file in model


json:popen(Charstring cmd)->Record

json:request(Charstring url)->Record

Read a JSON object from REST server in url


json:sample(Charstring url,Number period)->Stream of Record

Read a JSON object from REST server in url every period seconds


json:serial_stream(Charstring sn,Integer br)->Stream

json stream from serial port named sp with baud rate br


json:serial_stream(Charstring sn,Integer br,Charstring flow_control,
Integer data_bits,Integer stop_bits,Integer parity)->Stream

json stream from serial port named sp with baud rate br


json:socket_stream(Charstring host,Integer sp,Object request)->Stream

json stream from port sp on host


json:socket_stream(Charstring host,Integer sp)->Stream

json stream from port sp on host


json:stringify(Object o)->Charstring

json:unload(Vector of Function fnol,Charstring model,Charstring file)
->Charstring

Unload functions fnol into JSON file in model


json:unload(Charstring fn,Charstring model,Charstring file)->Charstring

Unload function named fn as JSON file in model on server


json:unstringify(Charstring string)->Object

json:unstringify_record(Charstring string)->Record

json:write_file(Charstring file,Stream s)->Charstring

Write elements in stream s into file in JSON format


json:write_file(Charstring file,Bag b)->Charstring

Write elements in bag b into file in JSON format


label_vector(Vector labels,Vector values)->Record

Label the elements in vector v with corresponding labels


make_record(Vector v)->Record

Construct a record from a vector v of keys followed by values


merge(Record x,Record y)->Record

Combine records x and y


put_record(Record r,Charstring k,Object v)->Record

Set value of key k in record r to value v


recordof(Bag of (Object,Object))->Record

Construct a record from a bag of attribute/value pairs b


record_length(Record r)->Integer

The number of key/value pairs in a record r


record_vector(Record r)->Vector v

vref(Record r,Object k)->Object

Same as r[k] access value of key k in record r