JsonDoc

Gem Version Build Status Coverage Status Dependency Status Code Climate Scrutinizer Code Quality Downloads Docs License

Generic JSON document base class to set/get document attributes based on JSON Schema, dump as JSON and support building of CSV and Excel workbooks. Subclasses can be built with additional functionality, e.g. using the setAttr method. Primary use cases include being used with parsers to create JSON documents and to create CSV/Excel reports.

Installation

Via Bundler

Add jsondoc to Gemfile and then run bundle:

$ echo "gem 'jsondoc'" >> Gemfile
$ bundle

Via RubyGems

$ gem install jsondoc

Usage

require 'jsondoc'

my_data = {}

my_schema = {
  type: 'My Document Type',
  properties: {
    first_name:      {type: 'string', description: 'First Name', default: ''},
    last_name:       {type: 'string', description: 'Last Name',  default: ''},
    email_addresses: {type: 'array' , description: 'Email Addresses', default: []}
  }
}

thisUser = JsonDoc::Document.new(my_data, my_schema)
thisUser.setAttr(:first_name, 'John')
thisUser.setAttr(:last_name,  'Doe')

first_name = thisUser.getAttr(:first_name)

thisUserHash = thisUser.asHash
thisUserJson = thisUser.asJson

descs  = thisUser.getDescArrayForProperties( [:first_name,:last_name] )
values = thisUser.getValArrayForProperties(  [:first_name,:last_name] )

thisUser.pushAttr(:email_addresses, '[email protected]')
thisUser.pushAttr(:email_addresses, '[email protected]')

thisUser.cpAttr(:first_name, :last_name)

Notes

Schema Validation

Schema validation is not provided in this version.

  1. JSON
  2. JSON Schema

License

JsonDoc is available under an MIT-style license. See LICENSE.txt for details.

JsonDoc © 2014-2016 by John Wang