Skip to content

NewtonsoftJson package update. Refactoring to improve scaling with large CSVs. - #52

Open
KRuusuv wants to merge 5 commits into
FrendsPlatform:mainfrom
KRuusuv:main
Open

NewtonsoftJson package update. Refactoring to improve scaling with large CSVs.#52
KRuusuv wants to merge 5 commits into
FrendsPlatform:mainfrom
KRuusuv:main

Conversation

@KRuusuv

@KRuusuv KRuusuv commented May 22, 2026

Copy link
Copy Markdown

Please review my changes :)


Review Checklist

  • Task version updated (x.x.0)
  • CHANGELOG.md updated
  • Solution builds
  • Warnings resolved (if possible)
  • Typos resolved
  • Tests cover new code
  • Description how to run tests locally added to README.md (if needed)
  • All tests pass locally

Summary by CodeRabbit

  • Chores

    • Bumped package version to 1.3.0
    • Updated Newtonsoft.Json dependency to 13.0.4 (including tests)
  • Refactor

    • JSON conversion now streams output to reduce memory usage and improve performance for large CSV files
    • Improved responsiveness by adding more frequent cancellation checks during conversion

Review Change Stack

KRuusuv and others added 3 commits May 22, 2026 16:24
…lower memory consumption and similar processing times when converting a 58 MB CSV and comparing to the most recent version of the ConvertToJson task. Tests with very small datasets showed a slight increase in processing time. Overall, the changes appear to come with a minor increase to constant overhead, but should provide slightly better scaling.

Note on dependencies: Newtonsoft.Json version was updated from 12.0.1 to 13.0.4
Memory usage optimizations and minor tweaks.
@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Walkthrough

ConvertToJSON now streams JSON output with JTokenWriter (per-row objects, cancellation-aware) instead of accumulating rows; projects upgraded to Newtonsoft.Json 13.0.4, package version bumped to 1.3.0, and CHANGELOG updated (2026-05-22).

Changes

CSV to JSON Streaming Refactor

Layer / File(s) Summary
Dependency versions and project metadata updates
Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.csproj, Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.Tests/Frends.CSV.ConvertToJSON.Tests.csproj
Project Version bumped to 1.3.0; Newtonsoft.Json upgraded to 13.0.4 in main and test projects; removed unused package references and minor project-file formatting adjustments.
JSON streaming implementation using JTokenWriter
Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs
ConvertToJSON refactored to initialize a JTokenWriter, start a top-level JSON array, and write each CSV row directly as a JSON object across three branches (column specs, header-row, no-header) with cancellation checks; removed WriteJsonString helper.
Changelog entry for 1.3.0 release
Frends.CSV.ConvertToJSON/CHANGELOG.md
Added ## [1.3.0] - 2026-05-22 entry documenting the Newtonsoft.Json 13.0.4 upgrade and streaming refactor to improve memory/performance for large CSV conversions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • jefim
  • MichalFrends1
  • MatteoDelOmbra

Poem

🐰 I nibble rows and write with care,
Streaming arrays into the air,
No bulky lists to make me stare,
Newtonsoft bumped — light as a hare! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the two main changes: Newtonsoft.Json package update (13.0.4) and refactoring for improved scaling with large CSV files via streaming JSON output.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
Frends.CSV.ConvertToJSON/CHANGELOG.md (1)

6-6: 💤 Low value

Consider more specific changelog description.

While the current description is acceptable, it could be more specific about what changed and the benefit to users. According to Keep a Changelog best practices, entries should clearly communicate what changed from a user perspective.

📝 Suggested improvement
-- Refactoring to improve scaling with large CSVs. 
+- Improved memory usage and performance when converting large CSV files by implementing streaming JSON output.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Frends.CSV.ConvertToJSON/CHANGELOG.md` at line 6, Update the CHANGELOG entry
that currently reads "Refactoring to improve scaling with large CSVs." to a more
specific user-facing description: state which components or functions were
refactored (e.g., streaming parser, memory buffering, or ReadAll-to-buffer
removal), describe the observable benefit (reduced memory usage, faster
processing, ability to handle N-GB files), and note any user-facing behavior
changes or configuration flags (if any), so the entry clearly explains what
changed and how it helps users.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Frends.CSV.ConvertToJSON/CHANGELOG.md`:
- Line 5: The changelog entry uses the incorrect package identifier
"NewtonsoftJson"; update the text to the correct NuGet package name
"Newtonsoft.Json" (include the period) so the line reads "Update package
Newtonsoft.Json to version 13.0.4."; ensure any other occurrences of
"NewtonsoftJson" in the change notes are similarly corrected.
- Line 3: The changelog dates for release headings are incorrect: update the
date string in the header "## [1.3.0] - 2025-05-12" to "## [1.3.0] - 2026-05-22"
and also correct the duplicated year for the "1.2.0" entry that currently shows
"2025-05-12" to the appropriate "2026-05-22" (or the actual release date if
different), ensuring both version headings reflect the correct year.

In
`@Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs`:
- Around line 121-137: The branch that handles a CSV with no headers writes the
first JSON object without checking for cancellation; before calling
writer.WriteStartObject() (and similarly before each
writer.WriteStartObject()/writer.WriteValue(...) sequence around the single-row
handling where headers, headerCount and index are used) add a cancellation check
such as cancellationToken.ThrowIfCancellationRequested() (or the existing
CancellationToken variable used in this class) so the method aborts and does not
return success when cancellation was requested.

---

Nitpick comments:
In `@Frends.CSV.ConvertToJSON/CHANGELOG.md`:
- Line 6: Update the CHANGELOG entry that currently reads "Refactoring to
improve scaling with large CSVs." to a more specific user-facing description:
state which components or functions were refactored (e.g., streaming parser,
memory buffering, or ReadAll-to-buffer removal), describe the observable benefit
(reduced memory usage, faster processing, ability to handle N-GB files), and
note any user-facing behavior changes or configuration flags (if any), so the
entry clearly explains what changed and how it helps users.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: afe5536f-7565-45fe-98e6-747aefde25a0

📥 Commits

Reviewing files that changed from the base of the PR and between aa32151 and f9e6776.

📒 Files selected for processing (4)
  • Frends.CSV.ConvertToJSON/CHANGELOG.md
  • Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.Tests/Frends.CSV.ConvertToJSON.Tests.csproj
  • Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs
  • Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.csproj

Comment thread Frends.CSV.ConvertToJSON/CHANGELOG.md Outdated
Comment thread Frends.CSV.ConvertToJSON/CHANGELOG.md Outdated
Comment thread Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs Outdated
KRuusuv added 2 commits May 22, 2026 17:49
…d writing the first line separately and without checking for cancellation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs (1)

132-145: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Check cancellation during final-row field serialization.

This loop only observes cancellation before WriteStartObject(). If the token is cancelled while writing fields for the last row, the method can still finish the object and return Success = true because there is no later check in this branch.

Suggested fix
             do
             {
                 cancellationToken.ThrowIfCancellationRequested();

                 writer.WriteStartObject();

                 for (var index = 0; index < headerCount; index++)
                 {
+                    cancellationToken.ThrowIfCancellationRequested();
                     writer.WritePropertyName(headers[index]);
                     writer.WriteValue(csvReader.GetField(index));
                 }

+                cancellationToken.ThrowIfCancellationRequested();
                 writer.WriteEndObject();
             } while (csvReader.Read());
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs`
around lines 132 - 145, The loop that serializes the final CSV row in the method
(the do/while block using csvReader, writer, headerCount and headers) only calls
cancellationToken.ThrowIfCancellationRequested() once at the top, so
cancellation during per-field writes can still complete and return success; fix
it by invoking cancellationToken.ThrowIfCancellationRequested() inside the for
loop before writing each field (and optionally again just before
writer.WriteEndObject()) so cancellation aborts mid-row, ensuring the method
honors the token during field serialization.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs`:
- Around line 132-145: The loop that serializes the final CSV row in the method
(the do/while block using csvReader, writer, headerCount and headers) only calls
cancellationToken.ThrowIfCancellationRequested() once at the top, so
cancellation during per-field writes can still complete and return success; fix
it by invoking cancellationToken.ThrowIfCancellationRequested() inside the for
loop before writing each field (and optionally again just before
writer.WriteEndObject()) so cancellation aborts mid-row, ensuring the method
honors the token during field serialization.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08939893-e020-4ea9-8572-bd963637cc28

📥 Commits

Reviewing files that changed from the base of the PR and between f9e6776 and 03464e9.

📒 Files selected for processing (3)
  • Frends.CSV.ConvertToJSON/CHANGELOG.md
  • Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.cs
  • Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.csproj
💤 Files with no reviewable changes (1)
  • Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON/Frends.CSV.ConvertToJSON.csproj
✅ Files skipped from review due to trivial changes (1)
  • Frends.CSV.ConvertToJSON/CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant