Skip to content

[Repo Assist] Add Frame.toJson / saveJson for JSON serialization#609

Merged
dsyme merged 3 commits intomasterfrom
repo-assist/fix-issue-556-frame-to-json-59d5a7f2b9e3644f
Mar 12, 2026
Merged

[Repo Assist] Add Frame.toJson / saveJson for JSON serialization#609
dsyme merged 3 commits intomasterfrom
repo-assist/fix-issue-556-frame-to-json-59d5a7f2b9e3644f

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Mar 9, 2026

🤖 Repo Assist — automated AI implementation in response to maintainer request.

Closes #556

Summary

Implements JSON serialization for Deedle data frames, mirroring pandas' to_json API. No new dependencies are introduced — JSON is written using a simple TextWriter-based approach.

New API

F# module functions

// Returns a JSON string
df |> Frame.toJson "columns"   // column-major (default)
df |> Frame.toJson "index"     // row-major
df |> Frame.toJson "records"   // array of row objects

// Writes to a file
df |> Frame.saveJson "/tmp/out.json"

F# extension methods

df.ToJson()                       // defaults to "columns"
df.ToJson(orient = "records")
df.SaveJson("out.json")
df.SaveJson(writer)

C# static methods

Frame.ToJson(df)                  // "columns" orient
Frame.ToJson(df, "records")
Frame.SaveJson(df, "out.json")
Frame.SaveJson(df, writer)
```

## JSON orient modes

| orient | shape | example |
|--------|-------|---------|
| `"columns"` | column-major object | `{"col":{"row":v,...},...}` |
| `"index"` | row-major object | `{"row":{"col":v,...},...}` |
| `"records"` | array of row objects | `[{"col":v,...},...]` |

## Design notes

- **No new dependencies** — plain `TextWriter` with manual JSON escaping.
- `float`/`float32` NaN and ±Infinity → `null` (matching pandas default behaviour).
- `DateTime`/`DateTimeOffset` serialised as ISO 8601 round-trip strings (`"o"` format).
- All string keys and values are properly JSON-escaped (quotes, backslash, control chars).
- `OptionalValue(T)` column types are unwrapped, consistent with `SaveCsv`.
- Multi-level row keys are flattened to a single string with `" - "` as separator.

## Test status

```
All tests passed: 494 total (9 new JSON tests + 485 pre-existing)

Built and tested on Linux with dotnet test tests/Deedle.Tests/Deedle.Tests.fsproj -c Release.

Generated by Repo Assist for issue #556 ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

Closes #556

Implement JSON serialization support for Deedle data frames, supporting
three orientation modes (mirroring pandas to_json):

- "columns" (default): column-major {"col":{"row":v,...},...}
- "index": row-major {"row":{"col":v,...},...}
- "records": array of row objects [{"col":v,...},...]

New API surface:
- F# module: Frame.toJson orient frame, Frame.saveJson path frame
- F# extension methods: frame.ToJson(?orient), frame.SaveJson(writer,?orient), frame.SaveJson(path,?orient)
- C# static extension methods: Frame.ToJson(frame,orient), Frame.SaveJson(frame,writer,orient), Frame.SaveJson(frame,path,orient)

Implementation notes:
- No new dependencies; JSON is written with a simple manual TextWriter approach
- float/float32 NaN and Infinity serialize as null (consistent with pandas default)
- DateTime/DateTimeOffset keys and values use ISO 8601 round-trip format ("o")
- All string keys and values are properly escaped per the JSON spec
- OptionalValue<T> column types are unwrapped (consistent with SaveCsv)

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 9, 2026 13:03
@dsyme dsyme merged commit 74040b6 into master Mar 12, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-556-frame-to-json-59d5a7f2b9e3644f branch March 12, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exporting frames to a json

1 participant