Επεξεργασία

Κοινή χρήση μέσω


StringToArray (NoSQL query)

APPLIES TO: NoSQL

Converts a string expression to an array.

Syntax

StringToArray(<string_expr>)  

Arguments

Description
string_expr A string expression.

Return types

Returns an array.

Examples

The following example illustrates how this function works with various inputs.

SELECT VALUE {
    parseEmptyArray: StringToArray("[]"),
    parseArray: StringToArray('[ "coats", "gloves", "hats" ]'),
    complexArray: StringToArray('[ { "types": [ "coats", "gloves" ] }, [ "hats" ], 76, false, null ]'),
    nestedArray: StringToArray('[ [ "coats", "gloves" ], [ "hats" ] ]'),
    invalidArray: StringToArray("[ 'coats', 'gloves', 'hats' ]"),
    parseUndefined: StringToArray(undefined),
    parseNull: StringToArray(null)
}
[
  {
    "parseEmptyArray": [],
    "parseArray": [ "coats", "gloves", "hats" ],
    "complexArray": [
      {
        "types": [ "coats", "gloves" ]
      },
      [ "hats" ],
      76,
      false,
      null
    ],
    "nestedArray": [
      [ "coats", "gloves" ],
      [ "hats" ]
    ]
  }
]

Remarks

  • This function doesn't use the index.
  • If the expression can't be converted, the function returns undefined.
  • Nested string values must be written with double quotes to be valid.
  • Single quotes within the array aren't valid JSON. Even though single quotes are valid within a query, they don't parse to valid arrays. Strings within the array string must either be escaped \" or the surrounding quote must be a single quote.

Note

For more information on the JSON format, see https://json.org.