jsonl.cr v0.1.0

Crystal shard for handling JSONL (JSON Lines) parsing

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

Repository

jsonl.cr

Owner
Statistic
  • 1
  • 0
  • 0
  • 0
  • 1
  • 8 months ago
  • August 15, 2023
License

MIT License

Links
Synced at

Sat, 18 May 2024 01:51:07 GMT

Languages