Coder Social home page Coder Social logo

mixlib-json's Introduction

Mixlib::JSON

Mixlib::JSON handles choosing a JSON serialization library, and then using that library consistently.

It has the following preferences:

* YAJL-Ruby
* Json Gem
* ActiveSupport

It will first check to see if any of the above libraries are already loaded in memory - if so, it will use it. If not, it will attempt to load each library in order, and use it for serialzation.

The API is simple:

require 'mixlib/json'
Mixlib::JSON.encode({ :one => :two }) # Returns a JSON string
Mixlib::JSON.pretty({ :one => :two }) # Returns a JSON string, pretty formatted
Mixlib::JSON.decode('{"one":"two"}')  # Decodes a JSON string

One feature of this library is that it can handle JSON gem style object inflation. If your JSON data contains json_class, the class it refers to exists, and it has a from_json class method, we will pass the inflated object to that method. To enable this functionality, do the following:

Mixlib::JSON.create_objects = true

Before you decode a JSON object.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright and Licensing

Author

Adam Jacob (<[email protected]>)

Copyright

Copyright © 2010 Opscode, Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

mixlib-json's People

Contributors

adamhjk avatar

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.