Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ready for use with limitations

  • Loading branch information...
commit 6248665de566824c8e1c645c4b246870fa851cf5 1 parent 7bf61c3
Peter Ohler authored
View
12 .travis.yml
@@ -0,0 +1,12 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+ - jruby
+ - rbx
+ - rbx-19mode
+ - ree
+
+script:
+ - gem build oj.gemspec
+ - gem install oj-*
View
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2011, Peter Ohler
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ - Neither the name of Peter Ohler nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
0  README
No changes.
View
58 README.md
@@ -0,0 +1,58 @@
+# Oj gem
+A fast JSON parser and Object marshaller as a Ruby gem.
+
+## <a name="installation">Installation</a>
+ gem install oj
+
+## <a name="source">Source</a>
+
+*GitHub* *repo*: https://github.com/ohler55/oj
+
+*RubyGems* *repo*: https://rubygems.org/gems/oj
+
+## <a name="build_status">Build Status</a>
+
+[![Build Status](http://travis-ci.org/ohler55/oj.png)](http://travis-ci.org/ohler55/oj)
+
+## <a name="links">Links of Interest</a>
+
+## <a name="release">Release Notes</a>
+
+### Release 0.5
+
+This is the first release sith a version of 0.5 indicating it is only half
+done. Basic load() and dump() is supported for Hash, Array, NilClass,
+TrueClass, FalseClass, Fixnum, Float, Symbol, and String Objects.
+
+## <a name="description">Description</a>
+
+Optimized JSON (Oj), as the name implies was written to provide speed
+optimized JSON handling. It was designed as a faster alternative to Yajl and
+other the common Ruby JSON parsers. So far is has achieved that at about 2
+time faster than Yajl for parsing and 3 or more times faster writing JSON.
+
+Coming soon: As an Object marshaller with support for circular references.
+
+Coming soon: A SAX like JSON stream parser.
+
+Oj is compatible with Ruby 1.8.7, 1.9.2, 1.9.3, JRuby, and RBX.
+
+### Simple JSON Writing and Parsing:
+
+ require 'oj'
+
+ h = { 'one' => 1, 'array' => [ true, false ] }
+ json = Oj.dump(h)
+
+ # json =
+ # {
+ # "one":1,
+ # "array":[
+ # true,
+ # false
+ # ]
+ # }
+
+ h2 = Oj.parse(json)
+ puts "Same? #{h == h2}"
+ # true
View
21 ext/oj/dump.c
@@ -274,13 +274,12 @@ dump_cstr(const char *str, int cnt, Out out) {
}
*out->cur++ = '"';
} else {
- // TBD maybe use ruby to generate string
size += 2;
if (out->end - out->cur <= (long)size) {
grow(out, size);
}
*out->cur++ = '"';
- for (; '\0' != *str; str++) {
+ for (; 0 < cnt; cnt--, str++) {
switch (json_friendly_chars[(u_char)*str]) {
case 'o':
*out->cur++ = *str;
@@ -294,7 +293,6 @@ dump_cstr(const char *str, int cnt, Out out) {
case '\f': *out->cur++ = 'f'; break;
case '\r': *out->cur++ = 'r'; break;
default: *out->cur++ = *str; break;
- break;
}
break;
case 'u':
@@ -312,8 +310,7 @@ dump_cstr(const char *str, int cnt, Out out) {
}
break;
default:
- // TBD raise
- break;
+ break; // ignore, should never happen if the table is correct
}
}
*out->cur++ = '"';
@@ -406,7 +403,6 @@ dump_hash(VALUE obj, int depth, Out out) {
fill_indent(out, depth);
*out->cur++ = '}';
}
- // TBD
*out->cur = '\0';
}
@@ -418,13 +414,22 @@ dump_val(VALUE obj, int depth, Out out) {
case T_FALSE: dump_false(out); break;
case T_FIXNUM: dump_fixnum(obj, out); break;
case T_FLOAT: dump_float(obj, out); break;
- // BIGNUM
+ case T_BIGNUM: break; // TBD
case T_STRING: dump_str(obj, out); break;
case T_SYMBOL: dump_sym(obj, out); break;
case T_ARRAY: dump_array(obj, depth, out); break;
case T_HASH: dump_hash(obj, depth, out); break;
+ case T_OBJECT:
+ case T_REGEXP:
+ case T_CLASS:
+ case T_DATA: // for Time
+ // TBD
+ rb_raise(rb_eNotImpError, "Failed to dump '%s' Object (%02x)\n",
+ rb_class2name(rb_obj_class(obj)), rb_type(obj));
+ break;
default:
- // TBD raise, call json, or leave as nil, or get all variables
+ rb_raise(rb_eNotImpError, "Failed to dump '%s' Object (%02x)\n",
+ rb_class2name(rb_obj_class(obj)), rb_type(obj));
break;
}
}
View
5 lib/oj/version.rb
@@ -0,0 +1,5 @@
+
+module Oj
+ # Current version of the module.
+ VERSION = '0.5'
+end
View
34 notes
@@ -3,17 +3,45 @@
^c^d hide subtree
^c^s show subtree
-- json object format
+- yajl-ruby is fastest out there until now
-- yajl-ruby is fastest out there
+- next
+ - document
+ - add options
+ - indent
+ - mode (object or simple)
+ - effort (strict, tolerant, lazy)
- load
- options
- encoding
- object or raw/simple
+ - todo
+ - bignum
- dump
- options
- indent
- object or simple (needed for Hash)
- - call sjon on objects, skip, or raise
+ - call sjon on objects, skip, or raise
+ - strict - raise
+ - lazy / nil
+ - tolerant / best effort
+ - use to_hash if respond_to
+ - use to_json if respond_to
+ - walk attributes
+
+ - todo
+ - multibyte group encoding
+ - bignum
+ - object and other types of object dumping
+
+
+- use stream and a sax like parser and writer
+
+- serialize/deserialize any object
+ - add class as first key in an object hash or make class and vars keys only (id for circular later)
+
+- support circular object encoding
+
+
View
32 oj.gemspec
@@ -0,0 +1,32 @@
+
+require 'date'
+require File.join(File.dirname(__FILE__), 'lib/oj/version')
+
+Gem::Specification.new do |s|
+ s.name = "oj"
+ s.version = ::Oj::VERSION
+ s.authors = "Peter Ohler"
+ s.date = Date.today.to_s
+ s.email = "peter@ohler.com"
+ s.homepage = "https://github.com/ohler55/oj"
+ s.summary = "A fast JSON parser and serializer."
+ s.description = %{A fast JSON parser and object serializer that uses only standard C lib.
+
+Optimized JSON (Oj), as the name implies was written to provide speed optimized
+JSON handling. It was designed to be an alternative to Yajl and other Ruby
+JSON parsers and as an alternative to Marshal for Object serialization. }
+
+# s.files = Dir["{lib,ext,test}/**/*.{rb,h,c}"] + ['LICENSE', 'README.md']
+ s.files = Dir["{lib,ext}/**/*.{rb,h,c}"] + ['LICENSE', 'README.md']
+
+ s.extensions = ["ext/oj/extconf.rb"]
+ # s.executables = []
+
+ s.require_paths = ["lib", "ext"]
+
+ s.has_rdoc = true
+ s.extra_rdoc_files = ['README.md']
+ s.rdoc_options = ['--main', 'README.md']
+
+ s.rubyforge_project = 'oj'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.