From 09a7a0c94f961096a3159199eaec4ab61988308a Mon Sep 17 00:00:00 2001 From: Victor Marin <36818606+mdvictor@users.noreply.github.com> Date: Thu, 13 Nov 2025 22:11:10 +0200 Subject: [PATCH] CSV Export: FieldType.other objects will be stringified (#113854) --- packages/grafana-data/src/utils/csv.test.ts | 20 ++++++++++++++++++++ packages/grafana-data/src/utils/csv.ts | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/grafana-data/src/utils/csv.test.ts b/packages/grafana-data/src/utils/csv.test.ts index 86e8e7ad907..3403d3bf7d6 100644 --- a/packages/grafana-data/src/utils/csv.test.ts +++ b/packages/grafana-data/src/utils/csv.test.ts @@ -181,6 +181,26 @@ describe('DataFrame to CSV', () => { `); }); + it('should handle field type other', () => { + const dataFrame = new MutableDataFrame({ + fields: [ + { name: 'Time', values: [1589455688623, 1589455692345] }, + { + name: 'Value', + type: FieldType.other, + values: [{ text: 'value1' }, { text: 'value2' }], + }, + ], + }); + + const csv = toCSV([dataFrame]); + expect(csv).toMatchInlineSnapshot(` + ""Time","Value" + 1589455688623,"{""text"":""value1""}" + 1589455692345,"{""text"":""value2""}"" + `); + }); + it('should handle null values', () => { const dataFrame = new MutableDataFrame({ fields: [ diff --git a/packages/grafana-data/src/utils/csv.ts b/packages/grafana-data/src/utils/csv.ts index 9823aa4c550..4aece4c1f8e 100644 --- a/packages/grafana-data/src/utils/csv.ts +++ b/packages/grafana-data/src/utils/csv.ts @@ -1,5 +1,5 @@ // Libraries -import { defaults } from 'lodash'; +import { defaults, isObject } from 'lodash'; import Papa, { ParseConfig, Parser, ParseResult } from 'papaparse'; // Types @@ -317,6 +317,10 @@ export function toCSV(data: DataFrame[], config?: CSVConfig): string { v = v.value; } + if (fields[j].type === FieldType.other && isObject(v)) { + v = JSON.stringify(v); + } + csv += writers[j](v); } }