GithubHelp home page GithubHelp logo

moran's Introduction

moran

moran (mo-RAN) is a simple JSON parser and generator for RubyMotion Android. It provides a Ruby wrapper around the Jackson JSON parser for Java.

moran emulates the standard Ruby JSON API, providing parse and generate methods:

hash = Moran.parse(json_string)
json_string = Moran.generate(hash)

It also adds convenience methods to Hash for generating JSON, and converting org.json.JSONObject instances into Hashes, which is handy for integrating with the Java libraries that use them:

json_string = hash.to_json
hash = Hash.from_json_object(some_json_object)

Setup

Prerequisite

This gem uses motion-gradle to manage the Java dependencies, so you need to have Gradle installed. For full details, see the motion-gradle README, but the basics are:

brew install gradle

then install Extras/Android Support Repository with the Android SDK Manager.

Project Setup

Gemfile:

gem "moran"

Install Gradle dependencies:

rake gradle:install

IMPORTANT NOTE ON motion-gradle COMPATIBILITY

Earlier versions of motion-gradle used a syntax that is no longer supported as of version 2.0. If you need to use a pre-2.0 version of motion-gradle, you should use version 0.7 of moran - this is the last version that works with pre-2.0 motion-gradle.

Usage

Parsing

json = '{ my_dog: "has_fleas" }'
hash = Moran.parse(json)
hash["my_dog"]  => "has_fleas"

Generating

hash = { dog: { name: "Rex", fleas: true } }
json = Moran.generate(hash)
# or...
json = hash.to_json

Converting org.json.JSONObject instances

json_obj = Org::Json::JSONObject.new
json_obj.put("string", "dog")
json_obj.put("boolean", true)

hash = Hash.from_json_object(json_obj)
hash["string"]  => "dog"
hash["boolean"] => true

Development

Tests

There is a small suite of tests that covers the basics, and can be run the usual way:

rake spec

or

rake spec:device

What's in a name?

Moran was named after jazz pianist and composer Jason Moran

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.