Skip to content

fix csvjsonarray emitting invalid JSON when label-quotes is passed - #23115

Merged
ktsaou merged 1 commit into
netdata:masterfrom
ktsaou:csvjsonarray-label-quotes
Jul 13, 2026
Merged

fix csvjsonarray emitting invalid JSON when label-quotes is passed#23115
ktsaou merged 1 commit into
netdata:masterfrom
ktsaou:csvjsonarray-label-quotes

Conversation

@ktsaou

@ktsaou ktsaou commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

The csvjsonarray formatter adds RRDR_OPTION_LABEL_QUOTES to the options it passes to rrdr2csv() using arithmetic addition instead of bitwise OR (options + RRDR_OPTION_LABEL_QUOTES, two call sites in rrd2json.c). When the caller already passes label-quotes — redundant but legal, since csvjsonarray always wants quoted labels — the addition clears the bit and carries into the next one. The header row is then emitted without quotes:

"result":[[time,a,b,c],
[1700000060,1,2,5],

— making the entire response invalid JSON. The carried-into bit is inert at format time (value conversion reads the query window options, which are untouched), so the values themselves stay correct.

Reachable on /api/v1, /api/v2 and /api/v3 data queries with format=csvjsonarray&options=label-quotes, at both call sites (with and without jsonwrap).

Fix

+| at both sites. A repository-wide search confirms these are the only two occurrences of arithmetic on RRDR_OPTION_* bits.

Validation

Red/green with a deterministic fixture (one chart, three dimensions, fixed 2023 epoch), covering both call sites:

  • RED (master): with label-quotes both v3+jsonwrap and v1 plain responses are invalid JSON (unquoted header); without it, valid JSON with correct raw values.
  • GREEN (this branch): both variants parse and produce identical result rows.

Related finding (not addressed here)

While validating this, a separate defect surfaced: /api/v{2,3}/data?format=csvjsonarray without seconds emits unquoted datetime strings ([2023-11-15 00:14:20,1,2,5]) — invalid JSON regardless of this fix. v1 avoids it only because its defaults include seconds. That needs a small contract decision (quote the dates vs default csvjsonarray to seconds on v2/v3) and will be handled separately.


Summary by cubic

Fixes invalid JSON from csvjsonarray when callers pass label-quotes by using bitwise OR to keep header labels quoted. /api/v1, /api/v2, and /api/v3 responses are now valid JSON in this case.

  • Bug Fixes
    • Use options | RRDR_OPTION_LABEL_QUOTES instead of options + RRDR_OPTION_LABEL_QUOTES at both rrdr2csv() call sites in src/web/api/formatters/rrd2json.c.
    • Prevents unquoted header rows (e.g., [time,a,b,c]) when label-quotes is redundantly supplied.

Written for commit 7e38c70. Summary will update on new commits.

Review in cubic

The csvjsonarray formatter adds RRDR_OPTION_LABEL_QUOTES to the options it
passes to rrdr2csv using arithmetic addition instead of bitwise OR. When
the caller already passes label-quotes (redundant but legal), the addition
clears the bit and carries into the next one, so the header row is emitted
without quotes - [time,a,b,c] - making the entire response invalid JSON.
The carried-into bit is inert at format time, so the values themselves
stay correct.

Reachable on /api/v1, /api/v2 and /api/v3 data queries with
format=csvjsonarray and options=label-quotes, at both call sites (with and
without jsonwrap).
@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@ktsaou
ktsaou merged commit ff4e3f4 into netdata:master Jul 13, 2026
124 of 140 checks passed
@stelfrag stelfrag mentioned this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant