Skip to content
/ jsonl.cr Public

Crystal shard for handling JSONL (JSON Lines) parsing

License

Notifications You must be signed in to change notification settings

Sija/jsonl.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONL

CI Releases License

JSONL is a module for handling JSONL (JSON Lines) parsing.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      jsonl:
        github: Sija/jsonl.cr
  2. Run shards install

Usage

require "jsonl"
arr = JSONL.parse <<-JSONL
  {"foo": "bar"}
  [1, 2, 3]
  "foo"
  JSONL

arr.class # => Array(JSON::Any)
class User
  include JSON::Serializable

  property id : Int32
  property first_name : String
  property last_name : String
end

input = <<-JSONL
  {"id": 1, "first_name": "John", "last_name": "Doe"}
  {"id": 2, "first_name": "Mary", "last_name": "Poppins"}
  {"id": 3, "first_name": "Jack", "last_name": "Black"}
  JSONL

users = User.from_jsonl(input)
users.class # => Array(User)

# no array allocation here
User.from_jsonl(input) do |user|
  user.class # => User
end

Contributing

  1. Fork it (https://github.com/Sija/jsonl.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors