Skip to content

Add Go CSV parser implementation with jsonic plugin#1

Merged
rjrodger merged 2 commits intomainfrom
claude/go-jsonic-implementation-ScdZ4
Mar 5, 2026
Merged

Add Go CSV parser implementation with jsonic plugin#1
rjrodger merged 2 commits intomainfrom
claude/go-jsonic-implementation-ScdZ4

Conversation

@rjrodger
Copy link
Contributor

@rjrodger rjrodger commented Mar 5, 2026

Summary

This PR adds a complete CSV parser implementation for Go with support for the jsonic plugin system. The implementation provides RFC 4180-compliant CSV parsing with extensive configuration options and a comprehensive test suite.

Key Changes

Core Parser Implementation (go/csv.go)

  • Implements Parse() function for parsing CSV text with configurable options
  • Supports RFC 4180 quoted field handling with double-quote escaping
  • Configurable field and record separators (default: comma and newline)
  • Optional value transformations:
    • Whitespace trimming
    • Number parsing (integers and floats)
    • Boolean/null keyword recognition
    • Comment line support (lines starting with #)
  • Streaming callback support for processing records as they're parsed
  • Maintains field order through orderedMap type for consistent JSON comparison

Plugin Integration (go/plugin.go)

  • Csv plugin function for jsonic integration with high-priority matcher
  • MakeJsonic() factory function for creating pre-configured jsonic instances
  • mapToOptions() helper to convert plugin configuration maps to CsvOptions
  • Automatic normalization of internal types for jsonic compatibility

Configuration Options

  • CsvOptions: Main configuration struct with boolean pointers for optional settings
  • FieldOptions: Field-level configuration (separator, naming, empty field handling)
  • RecordOptions: Record-level configuration (custom separators, empty record preservation)
  • Strict mode (default true) that disables automatic transformations; non-strict mode enables trim/comment/number by default

Test Suite (go/csv_test.go)

  • Fixture-based testing framework loading test cases from test/fixtures/manifest.json
  • 20+ test fixtures covering:
    • Basic CSV parsing with headers
    • Array vs object output formats
    • Quoted fields with embedded newlines and escaped quotes
    • Custom field and record separators
    • Comment handling (line and inline)
    • Value transformations (trim, number, boolean/null parsing)
    • Empty record handling
    • CRLF and various line ending formats
  • Unit tests for plugin interfaces and streaming callbacks
  • Helper functions for test assertions and value normalization

Test Fixtures

  • CSV test files with corresponding expected JSON output
  • Manifest configuration defining test parameters and options
  • Coverage of edge cases: empty fields, trailing newlines, leading newlines, multi-character separators

Build Configuration

  • Go module definition (go/go.mod) with jsonic dependency

Notable Implementation Details

  • Parser State Machine: Uses position-based parsing with lookahead for separator detection
  • Quote Handling: Implements RFC 4180 double-quote escaping (""")
  • Flexible Separators: Supports multi-character field and record separators
  • Ordered Maps: Preserves field insertion order for deterministic JSON output in tests
  • Streaming Support: Optional callback interface for processing records without buffering entire result
  • Strict vs Non-Strict Modes: Allows different default behaviors for transformation options
  • Empty Record Handling: Distinguishes between truly empty records and records with empty fields

https://claude.ai/code/session_01Ehie1ims4jJtda9A6MmD1x

claude added 2 commits March 5, 2026 12:24
- Create go/ directory with CSV parser using github.com/jsonicjs/jsonic/go v0.1.4
- Implement standalone Parse() function with full CSV options parity:
  object, header, trim, comment, number, value, field separators,
  record separators, empty records, streaming, double-quote escaping
- Provide MakeJsonic() for jsonic integration and Csv plugin via j.Use()
- Create test/fixtures/ with manifest.json and 24 fixture test cases
  (CSV/JSON pairs) shared between TypeScript and Go implementations
- All 24 fixture tests plus 14 unit tests pass

https://claude.ai/code/session_01Ehie1ims4jJtda9A6MmD1x
Un-ignore test/fixtures/*.csv so the shared test fixture CSV files
are tracked in git alongside their expected JSON outputs.

https://claude.ai/code/session_01Ehie1ims4jJtda9A6MmD1x
@rjrodger rjrodger merged commit 368b77c into main Mar 5, 2026
2 of 11 checks passed
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.

2 participants