Functions to read, write and manage JSON Objects

Version :
16.10.2024, 11:40 Uhr

Functions to read, write and manage JSON Objects

static JSON alloc(char* jsonString = 0)

Allocate a new JSON object. The object must be released with json::release

Name Type Default Description
Return JSON   JSON object. The object must be released with json::release.

0 : object could not be allocated or error when parsing the (optional) JSON string
jsonString String or char* 0 JSON string. If provided, the JSON object is initialized using this value.

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

parse_object
parse_array
read
release

static JSON parse_object(char* jsonString)

Parse a new JSON object from a given JSON string. This function is equivalent to json::alloc with mandatory jsaonString parameter.

Name Type Default Description
Return JSON   JSON object. The object must be released with json::release

0 : object could not be allocated or error when parsing the JSON string.
jsonString String or char* - JSON string

Check, whether a string represents a json object (i.e. ).

int main ()
{
    JSON test = json::parse_object ("{\"message\" : \"could be valid or not\", \"code\" : 123}");
if (test) { // valid json string, release json::release(test); } else { // ... }
return 0; }

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

alloc
parse_array
read
release

static StringList parse_array(char* jsonString)

Parse a new JSON object from a given JSON string. This function is equivalent to json::alloc with mandatory jsaonString parameter.

Name Type Default Description
Return JSON   JSON object. The object must be released with json::release

0 : object could not be allocated or error when parsing the JSON string.
jsonString String or char* - JSON string

v4.2 R32034, 17. Dez 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

alloc
parse_object
read
release

static JSON read(char* path)

Allocate a new JSON object from an input file in JSON format. The object must be released with json::release

Name Type Default Description
Return JSON   JSON object. The object must be released with json::release

0 : object could not be allocated or error when parsing the JSON string.
jsonString String or char* - Complete path of a JSON file

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

alloc
parse_object
parse_array
release

static int write(JSON json, char* path)

Write a JSON object to an output file.

Name Type Default Description
Return int   0 or Error Code
json JSON - Valid JSON object
path String oder char* - Complete path of the output file. If the file already exists, it will be overwritten. If a folder with the same name exists, the error fnfErr is returned.

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

read
serialize

static int release(JSON jsonObject)

Release an allocated JSON object.

Only objects that have been allocated with json::alloc, json::parse_object, json::parse_array or json::read may be released. JSON objects from calls to json::get_object must not be released! These objects are released by their parent object.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

alloc
parse_object
parse_array
read

static int set_string(
  JSON jsonObject,
  char* property,
  char* value)

Set the value of a property of a JSON object. The value is transferred as a character string.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object
value String or char* - New value of the property as a character string

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

get_string
get_type

static int set_int(
  JSON jsonObject,
  char* property,
  int value)

Set the value of a property of a JSON object. The value is given as integer.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object
value int - New value of the property given as integer

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

get_int
get_type

static int set_float(
  JSON jsonObject,
  char* property,
  float value)

Set the value of a property of a JSON object. The value is given as a floating point number.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object
value float - New value of the property given as floating point number

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

get_float
get_type

static int set_list(
  JSON jsonObject,
  char* property,
  StringList value)

Set the value of a property of a JSON object. The value is given as a list of strings.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object
value StringList - New value of the property given as list of strings

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

get_list
get_type

static int set_object(
  JSON jsonObject,
  char* property,
  JSON value)

Insert a JSON sub-object into a JSON object.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object
value JSON - Valid JSON object as a sub-object of the given object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

get_object
get_type

static int set_error(
  JSON jsonObject,
  int errorCode,
  char* errorClass = 0,
  char* errorMessage = 0)

Set a JSON error.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
errorCode int - Set the attribute errorCode of the given JSON object
errorClass String oder char* - Set the attribute errorClass of the given JSON object
errorMessage String oder char* - Set the attribute errorMessage of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

get_object

static StringList get_attributes(JSON jsonObject)

Get a list of all attribute names of a JSON object.

The received list of attribute names must be released again with stringlist::release!

Name Type Default Description
Return StringList   List of all attribute names of the JSON object. The received list must be released again with stringlist::release!
jsonObject JSON - Valid JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

stringlist::release

static int get_type(JSON jsonObject, char* property)

Determine the data type of a JSON attribute.

Name Type Default Description
Return int   0 : No type or error
1 : kInt
2 : kFloat
3 : kString
7 : kStringList
8 : kObject (JSON object)
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

static char* get_string(JSON jsonObject, char* property)

Determine the string value of a property of a JSON object.

Name Type Default Description
Return char*   Text value of the attribute or 0

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

set_string
get_type

static int get_int(JSON jsonObject, char* property)

Name Type Default Description
Return int   Integer value of the property or 0. Please note that 0 can be both an error and a value. In this case, check the existence and type of the attribute!
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

set_int
get_type

static int get_float(JSON jsonObject, char* property)

Determine the floating-point value of a property of a JSON object.

Name Type Default Description
Return int   Float value of the property or 0.0. Please note that 0 can be both an error and a value. In this case, check the existence and type of the attribute!
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

set_float
get_type

static StringList get_list(JSON jsonObject, char* property)

Determine the list of values of a JSON attribute.

The list of values received must be released again with stringlist::release!

Name Type Default Description
Return StringList   Value list of the JSON attribute The received list must be released again with stringlist::release!
jsonObject JSON - Valid JSON object
property String or char* - Valid name of a property of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

set_list
get_type
stringlist::release

static JSON get_object(JSON jsonObject, char* property)

Get a sub-object of a JSON object.

Name Type Default Description
Return JSON   Subobject of the searched name or 0
jsonObject JSON - Valid JSON object
property String or char* - Valid name of the sub-object of the given JSON object

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

set_object
get_type

static int get_error(
  JSON jsonObject,
  char* errorClass = 0,
  char* errorMessage = 0)

Get the error description stored in the JSON object.

Name Type Default Description
Return int   Value of attribute errorCode
jsonObject JSON - Valid JSON object
errorClass String oder char* - Allokierter Speicher für das Attribut errorClass des gegebenen JSON-Objektes
errorMessage String oder char* - Allokierter Speicher für das Attribut errorMessage des gegebenen JSON-Objektes

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

set_error

static int serialize(JSON jsonObject, char* destination)

Export a given JSON to a string.

Name Type Default Description
Return int   0 or Error Code
jsonObject JSON - Valid JSON object
destination String oder char* - Allocated memory for the result. Since you do not know the exact length, it is recommended to use a varibale of type String here!

v4.2 R32034, 17. Dec 2022

priint:comet InDesign® Plug-Ins, Illustrator, comet_pdf

write

Version
16.10.2024, 11:40 Uhr
Since
Plugin Version 4.3.0 (available "at your own risk" in 4.2.0)

Alphabetic index HTML hierarchy of classes or Java