No release in over a year
This gem provides utilities for reading, filtering, mapping, and writing JSON Lines formatted files in Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 2.0
 Project Readme

JSONL Reader Writer

jsonl_reader_writer is a Ruby gem that provides utilities for reading, mapping, filtering, and writing JSON Lines formatted files.

Installation

Add this line to your application's Gemfile:

gem 'jsonl_reader_writer'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install jsonl_reader_writer

Usage

require 'jsonl_reader_writer'

# Create a reader instance
reader = JsonlReaderWriter::Reader.new('/path/to/your/jsonl_file.jsonl')

# Read and print each line
reader.each do |data, line_number|
  puts "Line #{line_number + 1}: #{data}"
end

# Filter the data
filtered_data = reader.filter do |data|
  data['some_key'] == 'some_value'
end

# Map the data
mapped_data = reader.map do |data|
  data['some_key']
end

# Create a writer instance
writer = JsonlReaderWriter::Writer.new('/path/to/your/output_file.jsonl')

# Write data
writer.write({ some_key: 'some_value' })

# Write multiple records
records = [
  { record_1_key: 'record_1_value' },
  { record_2_key: 'record_2_value' },
]
writer.write(records)

# Write data with validation
writer.write({ some_key: 'some_value' }, validate: true)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ka2-ya/jsonl-reader-writer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.