4D v16.3Overview of JSON commands |
||||||||||||||||||||||||||||||||||
|
4D v16.3
Overview of JSON commands
Overview of JSON commands
JSON commands generate and parse JSON-format language objects. More particularly, JSON format makes it possible to access 4D databases (data and structure) using a Web browser. Support for structured objects is a major new feature of the language in 4D v14, intended to facilitate the exchange of structured data. Thanks to the commands of the "JSON" theme, 4D can work directly with JSON objects. However, 4D can also work with "native" objects (whose structure is inspired by JSON), allowing exchanges with all types of language. For more information, refer to the Objects (Language) chapter. "JSON or JavaScript Object Notation is a generic text-based data format derived from object notation of the ECMAScript language." (source: Wikipedia). JSON is independent from any other language, but uses conventions that are familiar to programmers using C++ or JavaScript, Perl, and so on. It is a format that is particularly suitable for data exchange. This section summarizes the notation principles implemented in JSON. For a complete description of this format, refer the following site: www.json.org/index.html. JSON syntax is based on the following principles:
JSON data is expressed in name/value (or key/value) pairs. A name/value pair contains a field name (in quotes), then a colon, followed by a value. For example: "firstName":"John" For information, this example is equivalent to the following in JavaScript: firstName="John" Keep in mind that property names are diacritical and case-sensitive. If you write "FirstName" instead of "firstName," this gives you a new name/value pair. The following types of values are supported in JSON:
JSON objects are defined by braces and can contain an undefined number of name/value pairs, for example: { "firstName":"John" , "lastName":"Doe" } JSON objects can be stored and handled in 4D through object variables (C_OBJECT) and fields. JSON arrays are defined by brackets. Each array can contain an undefined number of objects: { "employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ] } By default, when 4D dates are converted to and from JSON, they take into account the time zone of the machine where the conversion took place (in conformity with JavaScript). For example, in France (GMT+2), converting !23/08/2013! gives you "2013-08-22T22:00:00Z" and vice versa. You can change this functioning and no longer take the time zone into account, during the implementation of export procedures for example, using the SET DATABASE PARAMETER command. For more information about converting 4D/JSON dates, refer to Conversion of JavaScript dates.
See also
|
PROPERTIES
Product: 4D
HISTORY
ARTICLE USAGE
4D Language Reference ( 4D v16) |
||||||||||||||||||||||||||||||||