Class JSONSerialize

java.lang.Object
ortus.boxlang.runtime.bifs.BIF
ortus.boxlang.runtime.bifs.global.conversion.JSONSerialize

@BoxBIF(description="Convert BoxLang data to JSON string") @BoxMember(type=CUSTOM,customType=java.lang.Boolean.class,name="toJSON") @BoxMember(type=CUSTOM2,customType=java.lang.Number.class,name="toJSON") @BoxMember(type=ARRAY,name="toJSON") @BoxMember(type=CLASS,name="toJSON") @BoxMember(type=QUERY,name="toJSON") @BoxMember(type=STRUCT,name="toJSON") @BoxMember(type=STRING_STRICT,name="listToJSON") @BoxMember(type=STRING_STRICT,name="toJSON") public class JSONSerialize extends BIF
  • Constructor Details

    • JSONSerialize

      public JSONSerialize()
      Constructor
  • Method Details

    • _invoke

      public Object _invoke(IBoxContext context, ArgumentsScope arguments)
      Converts a BoxLang variable into a JSON (JavaScript Object Notation) string according to the specified options.

      Query Format Options

      The queryFormat argument determines how queries are serialized:
      • row or false: Serializes the query as a top-level struct with two keys: columns (an array of column names) and data (an array of arrays representing each row's data).
      • column or true: Serializes the query as a top-level struct with three keys: rowCount (the number of rows), columns (an array of column names), and data (a struct where each key is a column name and the value is an array of values for that column).
      • struct: Serializes the query as an array of structs, where each struct represents a row of data.

      Usage

       // Convert a query to JSON
       myQuery = ...;
       json = jsonSerialize( myQuery, queryFormat="row" );
       // Convert a list to JSON
       myList = "foo,bar,baz";
       jsonList = jsonSerialize( myList );
       
      Specified by:
      _invoke in class BIF
      Parameters:
      context - The context in which the BIF is being invoked.
      arguments - Argument scope for the BIF.
      Returns:
      The result of the invocation