4D v14.3

Overview of JSON commands

Home

 
4D v14.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:

  • data consists of name/value pairs,
  • data is separated by commas,
  • objects are defined by braces {},
  • arrays are defined by brackets [ ].

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:

TypeDescriptionComments
stringAny Unicode character except for " and \
Values, like property names, are in quotes ("), for example, "city":"Paris"
\ is used for control characters:
\" = quotes
\\ = backslash
\/ = slash
\b = backspace
\f = formfeed
\n = line break
\r = carriage return
\t = tab
\u = four hexadecimal digits
numberInteger or floating point numberNumber similar to a C or Java number, except that the octal and hexadecimal formats are not used
object{ }
array[ ]
booleantrue or false
nullnull

JSON objects are defined by braces and can contain an undefined number of name/value pairs, for example:

{ "firstName":"John" , "lastName":"Doe" }

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.

 
PROPERTIES 

Product: 4D
Theme: JSON

 
SEE ALSO 

Objects (Language)

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)