KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Behavior of JSON Parse with Arrays
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: September 14, 2017

JSON Parse is a useful command to convert json formated text into 4D object type variables. When using JSON Parse, there are a variety of outcomes based on the contents of the text being parsed.

The typical results based on passed text are:
1) With a valid JSON format text, for example the following will properly convert into a 4D object:

  {
    "Name":"Test",
    "Number":1
  }




2) An invalid JSON format text, for example the following will generate an error:

    "Hello World"



3) The lesser known result is when passing a JSON Array, when this occurs the array will properly parse and get converted, however the result becomes a Collection and not an Object even if there is only one element in the array. For example using the first example:

  [{
    "Name":"Test",
    "Number":1
  }]




So while the text may parse, it may not be entirely a valid object and as such may cause errors.