Skip to content

Conversation

@pahalsrivastava
Copy link
Contributor

Summary

This PR refactors the JSON output generation in r.kappa to use the
Parson JSON library instead of manual fprintf() calls.

Details

  • Replaces handcrafted JSON printing with Parson API calls
  • Preserves the existing JSON schema, field names, ordering, and semantics
  • Keeps null handling for na_value unchanged
  • Improves maintainability and reduces risk of malformed JSON

Related issue

Fixes #6968

Copy link
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

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

You have unrelated changes in your PR.

@github-actions github-actions bot added raster Related to raster data processing C Related code is in C C++ Related code is in C++ module docs markdown Related to markdown, markdown files labels Jan 27, 2026

json_object_set_string(root_object, "reference", maps[0]);
json_object_set_string(root_object, "classification", maps[1]);
json_object_set_number(root_object, "observations", (double)metrics->observations);
Copy link
Contributor

Choose a reason for hiding this comment

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

[clang-format] reported by reviewdog 🐶

Suggested change
json_object_set_number(root_object, "observations", (double)metrics->observations);
json_object_set_number(root_object, "observations",
(double)metrics->observations);
json_object_set_string(root_object, "classification", maps[1]);
json_object_set_number(root_object, "observations", (double)metrics->observations);
json_object_set_number(root_object, "correct", (double)metrics->correct);
json_object_set_number(root_object, "overall_accuracy", metrics->overall_accuracy);
Copy link
Contributor

Choose a reason for hiding this comment

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

[clang-format] reported by reviewdog 🐶

Suggested change
json_object_set_number(root_object, "overall_accuracy", metrics->overall_accuracy);
json_object_set_number(root_object, "overall_accuracy",
metrics->overall_accuracy);
else
fprintf(fd, "],\n [");
bool cfirst = 1;
json_object_set_number(root_object, "kappa_variance", metrics->kappa_variance);
Copy link
Contributor

Choose a reason for hiding this comment

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

[clang-format] reported by reviewdog 🐶

Suggested change
json_object_set_number(root_object, "kappa_variance", metrics->kappa_variance);
json_object_set_number(root_object, "kappa_variance",
metrics->kappa_variance);
JSON_Value *row_value = json_value_init_array();
JSON_Array *row_array = json_value_get_array(row_value);
for (int j = 0; j < ncat; j++)
json_array_append_number(row_array, (double)metrics->matrix[ncat * i + j]);
Copy link
Contributor

Choose a reason for hiding this comment

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

[clang-format] reported by reviewdog 🐶

Suggested change
json_array_append_number(row_array, (double)metrics->matrix[ncat * i + j]);
json_array_append_number(row_array,
(double)metrics->matrix[ncat * i + j]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C C++ Related code is in C++ docs markdown Related to markdown, markdown files module raster Related to raster data processing

2 participants