Skip to content

fix(sheets): preserve multi-row structure in +append --json-values#410

Open
anshul-garg27 wants to merge 3 commits intogoogleworkspace:mainfrom
anshul-garg27:fix/append-json-values-multi-row
Open

fix(sheets): preserve multi-row structure in +append --json-values#410
anshul-garg27 wants to merge 3 commits intogoogleworkspace:mainfrom
anshul-garg27:fix/append-json-values-multi-row

Conversation

@anshul-garg27
Copy link
Contributor

Summary

  • Fix +append --json-values flattening multi-row arrays into a single row
  • Change AppendConfig.values from Vec<String> to Vec<Vec<String>> to preserve row boundaries
  • Single-row inputs (--values and flat JSON arrays) are wrapped in a single-element outer vec for consistency

Root cause

parse_append_args called .flatten() on the parsed Vec<Vec<String>>, collapsing all rows into a single flat vector. Combined with build_append_request wrapping that flat vec in another array ("values": [config.values]), the Sheets API always received exactly one row regardless of input shape.

Before: [["Alice","100"],["Bob","200"]] → 1 row: Alice | 100 | Bob | 200
After: [["Alice","100"],["Bob","200"]] → 2 rows: Alice | 100 and Bob | 200

Test plan

  • Added test: --json-values with multi-row array preserves row structure
  • Added test: --json-values with single flat array wraps as one row
  • Added test: --values wraps comma-separated values as one row
  • Added test: build_append_request produces correct multi-row JSON body
  • Updated existing tests to match new Vec<Vec<String>> type

Closes #311

Previously, `parse_append_args` called `.flatten()` on the parsed
`Vec<Vec<String>>`, collapsing all rows into a single flat vector.
Combined with `build_append_request` wrapping the flat vec in another
array, this meant `[["Alice","100"],["Bob","200"]]` produced one row
with four columns instead of two rows with two columns each.

Change `AppendConfig.values` from `Vec<String>` to `Vec<Vec<String>>`
so row boundaries are preserved end-to-end. Single-row inputs via
`--values` and flat JSON arrays are wrapped in a single-element outer
vec for consistency.

Closes googleworkspace#311
@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: a881528

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 11, 2026
@google-cla
Copy link

google-cla bot commented Mar 11, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the +append --json-values command, which previously failed to correctly interpret and send multi-row data to the Google Sheets API. The core change involves updating the internal data structure for append values to explicitly support nested vectors, ensuring that row boundaries are preserved from input parsing through to the final API request. This enhancement significantly improves the reliability and flexibility of appending structured data, making the command behave as expected for various input formats.

Highlights

  • Multi-row JSON values fix: Resolved an issue where +append --json-values would flatten multi-row arrays into a single row, now correctly preserving the row structure.
  • Data structure update: The AppendConfig.values field was changed from Vec<String> to Vec<Vec<String>> to accurately represent and maintain row boundaries for appended data.
  • Consistent input handling: Ensured that both single-row inputs (from --values and flat JSON arrays) are consistently wrapped in a single-element outer vector, aligning with the new multi-row structure.
  • API request body correction: Removed an unnecessary extra array wrapper in the build_append_request function, which previously caused the Sheets API to always receive only one row.
  • Comprehensive testing: Added new tests to cover multi-row and single-row JSON value parsing, as well as the correct construction of multi-row API request bodies, and updated existing tests for type consistency.
Changelog
  • .changeset/fix-append-json-values-multi-row.md
    • Added a new changeset file documenting the fix for multi-row JSON values in the +append command.
  • src/helpers/sheets.rs
    • Modified build_append_request to remove an extraneous array wrapper around config.values in the JSON request body, allowing multi-row data to be sent correctly.
    • Updated the AppendConfig struct's values field type from Vec<String> to Vec<Vec<String>> to represent rows and columns accurately.
    • Refactored parse_append_args to correctly parse --json-values as either Vec<Vec<String>> for multi-row data or Vec<String> (wrapped into Vec<Vec<String>>) for single-row data.
    • Adjusted parse_append_args to wrap --values input into a Vec<Vec<String>> to maintain consistency with the new data structure.
    • Updated the test_build_append_request test to reflect the new Vec<Vec<String>> type for AppendConfig.values.
    • Renamed test_parse_append_args to test_parse_append_args_values and updated its assertion to match the new Vec<Vec<String>> type.
    • Added test_parse_append_args_json_single_row to verify correct parsing of flat JSON arrays as a single row.
    • Added test_parse_append_args_json_multi_row to confirm proper parsing of nested JSON arrays as multiple rows.
    • Introduced test_build_append_request_multi_row to ensure the generated API request body correctly contains multi-row data.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a bug in the +append --json-values command where multi-row arrays were incorrectly flattened into a single row before being sent to the Google Sheets API. The AppendConfig struct's values field has been updated from Vec<String> to Vec<Vec<String>> to correctly represent multiple rows. The parse_append_args function was refactored to properly parse both single and multi-row JSON inputs, as well as single-row comma-separated inputs, into this new Vec<Vec<String>> structure. Consequently, the build_append_request function now directly uses this multi-row structure for the API request body, ensuring the preservation of row integrity. New test cases were added to validate the correct parsing and API request body construction for various single and multi-row scenarios.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where multi-row JSON arrays were being flattened into a single row when using sheets +append --json-values. The change to use Vec<Vec<String>> throughout the call chain and the updated parsing logic are well-implemented. The new tests provide good coverage for the fix. I have one suggestion to improve error handling for malformed JSON input to provide a better user experience.

Address review feedback: print a warning to stderr when --json-values
cannot be parsed as a JSON array, rather than silently falling back
to an empty value set.
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a bug where the +append --json-values command incorrectly flattened multi-row arrays into a single row when sending data to the Google Sheets API. The AppendConfig struct's values field was updated from Vec<String> to Vec<Vec<String>> to properly represent multiple rows. The parse_append_args function was refactored to correctly parse both single and multi-row JSON inputs for --json-values and to ensure --values also produces a Vec<Vec<String>>. Additionally, the build_append_request function was adjusted to directly use this nested vector for the API request body, and new tests were added to validate the correct handling of single and multi-row data parsing and request construction.

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

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

+append --json-values flattens multi-row arrays into a single row

2 participants