--- title: "toJSON" slug: "calc-function-to-json" updated: 2026-05-12T13:54:11Z published: 2026-05-12T13:54:11Z canonical: "docs.lobstersoftware.com/calc-function-to-json" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # toJSON *See also*: [parseJSON](/v1/docs/en/calc-function-parse-json) > [!NOTE] > Serializes an object to the corresponding JSON representation. > > > [!TIP] > > Tooltip > > > > Syntax: *$toJSON(object[,format=false[,classField=class]])* > > > > | Parameter | Description | > > | --- | --- | > > | `object` | The object to be serialized. | > > | `format` | Optional, default value = false, true to generate a formatted JSON. | > > | `classField` | Optional, default value = "class", specifies the property in which the class name is to be searched. This may need to be set to "clazz". | > > | `forceNativeTypes` | Optional, default = false, true to enforce native JSON types, e.g. (long is written as JSON number, list is written as array). | > > > > Returns the object as a JSON string. > > > > Example: $toJSON($el(5)) ## Syntax *$toJSON(object[,format=false[,classField=class]])* ## Parameter | Name | Description | | --- | --- | | object | The object to be serialized. | | format | Optional, default value = false, true to generate a formatted JSON. | | *classField* | Optional, default value = "class", specifies the property in which the class name is to be searched. This may need to be set to "clazz". | ## Return value The object as JSON ## Example | Syntax | Result | | --- | --- | | $toJSON($el(12)) | "Element12SimpleText" | | $toJSON($el(11)) | ```json {"el12":"Element12SimpleText"} ``` | | $toJSON($el(11),$true) | ```json { "el12": "Element12SimpleText" } ``` |