TOJSON DAX Function (Text)

Converts the records of a table into a JSON text.


TOJSON ( <Table> [, <MaxRows>] )
Parameter Attributes Description

The table to be converted.

MaxRows Optional

The maximum number of rows to be converted. A negative number means all rows are converted. Default is 10.

Return values

Scalar A single string value.

Result in JSON format.


The sort order of the result cannot be controlled.

» 1 related function


DEFINE MEASURE Sales[ByCountry] =
	VAR SalesByCustomer = 
			VALUES ( Customer[CountryRegion] ), 
			"Amount", [Sales Amount] 
	VAR Result = TOJSON (  SalesByCustomer, 3  )
	RETURN Result
SUMMARIZECOLUMNS ( 'Customer'[Continent], "By Country JSON", [ByCountry] )
Continent By Country JSON
Asia {
“header”: [“‘Customer'[CountryRegion]”, “[Amount]”],
“rowCount”: 15,
“data”: [
[“Australia”, 7638059.9358],
[“Turkmenistan”, 118336.5519],
[“Thailand”, 63107.118]
North America {
“header”: [“‘Customer'[CountryRegion]”, “[Amount]”],
“rowCount”: 2,
“data”: [
[“United States”, 10312118.2484],
[“Canada”, 885208.0705]
Europe {
“header”: [“‘Customer'[CountryRegion]”, “[Amount]”],
“rowCount”: 12,
“data”: [
[“Germany”, 2519890.7983],
[“United Kingdom”, 3621032.1587],
[“France”, 1109665.4323]

Related functions

Other related functions are:

Last update: Jul 12, 2024   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber

Microsoft documentation:

2018-2024 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.


Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.


This function is deprecated. Jump to the Alternatives section to see the function to use.


A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.


This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.


Want to improve the content of TOJSON? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.