00fe4cae8403d5a453699e4b054ab627728abdca
[packages/precise/mcollective.git] / lib / mcollective / vendor / json / lib / json.rb
1 ##
2 # = JavaScript Object Notation (JSON)
3 #
4 # JSON is a lightweight data-interchange format. It is easy for us
5 # humans to read and write. Plus, equally simple for machines to generate or parse.
6 # JSON is completely language agnostic, making it the ideal interchange format.
7 #
8 # Built on two universally available structures:
9 #   1. A collection of name/value pairs. Often referred to as an _object_, hash table, record, struct, keyed list, or associative array.
10 #   2. An ordered list of values. More commonly called an _array_, vector, sequence or list.
11 #
12 # To read more about JSON visit: http://json.org
13 #
14 # == Parsing JSON
15 #
16 # To parse a JSON string received by another application or generated within
17 # your existing application:
18 #
19 #   require 'json'
20 #
21 #   my_hash = JSON.parse('{"hello": "goodbye"}')
22 #   puts my_hash["hello"] => "goodbye"
23 #
24 # Notice the extra quotes <tt>''</tt> around the hash notation. Ruby expects
25 # the argument to be a string and can't convert objects like a hash or array.
26 #
27 # Ruby converts your string into a hash
28 #
29 # == Generating JSON
30 #
31 # Creating a JSON string for communication or serialization is
32 # just as simple.
33 #
34 #   require 'json'
35 #
36 #   my_hash = {:hello => "goodbye"}
37 #   puts JSON.generate(my_hash) => "{\"hello\":\"goodbye\"}"
38 #
39 # Or an alternative way:
40 #
41 #   require 'json'
42 #   puts {:hello => "goodbye"}.to_json => "{\"hello\":\"goodbye\"}"
43 #
44 # <tt>JSON.generate</tt> only allows objects or arrays to be converted
45 # to JSON syntax. <tt>to_json</tt>, however, accepts many Ruby classes
46 # even though it acts only as a method for serialization:
47 #
48 #   require 'json'
49 #
50 #   1.to_json => "1"
51 #
52
53 require 'json/common'
54 module JSON
55   require 'json/version'
56
57   begin
58     require 'json/ext'
59   rescue LoadError
60     require 'json/pure'
61   end
62 end