����C %# , #&')*)-0-(0%()(��C (((((((((((((((((((((((((((((((((((((((((((((((((((����"�������@�@�hC��}!���Ѱ��<"� 9iׂIIIHk�+?�c?��*Y�����!�du)b�T�9вU�$8G��I.�澬��D���Sq� q�}.<��Z�l�V!X� *x�-�\����t3i�Ũ�sNv71�ƛ\��z|t�L���$�����*f��kʮ��7�H;���~F%�'3�@�H�q�` 9mOL����/x@ @��G
d�8F�ه��Ka�Kdr�Fh.�]y4 JЛ��]�K�B�E$��$ $ �PR�����G�]��u�i$�$���'! "#031���C/Td=S�Q?���62Ccj{ ����̏d�چ/c�V�`��Wz͈�{Y`�d�h�L �]OB���l���o���mr���n��s-ڗEZ��N�_��1%b���H�ϣ������V�7):�ӷ)�}�~�(�;�!�b1�5K��[E�vϻ>��q.%� ���O���(�c�#x�$�'+��`٥v��v(�����M�"�v��B��.�a ���T�~�ϕ�hy(6nݱl��1yNɓx�������AR�8�rqv1.cS�+��_���&@�� �u�M�5Ĉ�Xm���eL�X�q��y#�9]�c�}ɄL��d�eJ몓���I1T�d��CaM�$��T�,�X �bʭ�!�%F5��X1x#���!�q��\��F��2��&Rq���C�ol~�̱�.0ϦL�d�`.������ ���m{�Y~k{C��}bv�;U��c<�r�~ɜs�1�j��]W�l��*նCr��Q�N9�-������d��E؛��nF��eړ�8(q��5UgRȱGTA��*������̆��V�珰����ezN��h�U]�T�FG�^���<��ay�,!���5.� �u�bΚ�V�J%��m�Dxn'�����6�@BPa�`��Hts� �ɮ���Ŏ�Zɬ��%B�X��d5Z���hC}�䅸�p+ k=��ʒ(�aՏFG&�%@/�{+�Yu+�ȣGѩ"O%�|vȲxF>�N(��ou�h6 &Y5��8�7�E$-��']n,@TD\��+���Ry�U��U^�Q,f>��1�����q��f��U��� ����F���ڥ��>I�����fNUw�u��#OMMQ6� N�*��_�� k� ����rS��`���1�:��!�F'<+� � b?O��2 !Q12A��� "3a������#$��?�,�7�!`yǮ(�1�6w��a���� �F�#��?*"s���v>��Ⱥ����f�v��͑���s����������]Gn��S ���ȥpG ы�E�g�)Z���x�rY�q�]�@f�_܃�pչEڎّC ����Ŝ*/ �h�O�Sv�و\��5��U��y��|o�Hm2C�S�BW����)��5��{T��W���=o*RA��<����L0g4{��쁢�ep�rw�8��7��U���t<Ԍѻ7�fGf�k}���Ê�㛆Gռz�Q@��{C��'G��8�!�S$�j��x���|���צV<��,����u�k�uu�rM�f�_dϣi ߫�ԟn�!K����mxu�=�槻�'j�X�����������%!A "1QR#Br��?�R:��R�n�b[�II?#��6<:�$gN����lGNlrr��dעMMn`ɿy�,�%B�e�W��dVS��r���� %�tT��(�ɷ��S�]�O]#�_LEMHN�M���kv���~X���O6�U�V_�����b���J�t�774����D!1AQa"2q�#3BRb����0���� 4CSr����cst�����?��^q���7�dG�U�"p��moz��'��n_x���唹e������<6��O�t���R>k��s=�Cr���e�?�i��� ����/��ں$be���o`ޮ�GHy�;fNAl�8��.�\�S������"���a�úF�YvNk�-*`v�k�ʈ2f�EE��Wa�,� �fF^#�;��[9��^~������Y$:0#W3������Z*���I�Z�ڹ�k�n--9=��G��;7F)m{T�Ɇ��=�����Ȭ5�5�B�aڞ5M����#m�5Ʀ��m�8��+Hh���$�}�:&�e�Q�[;i]С�:�:��o����$<~��5RB�?�s3�5�r��O��ֿ�w�P/��̅���(�Z6�R>)��N��4�!ʊ�wz�-�r�w+�yk���q�1�bKhƸ�4N�Ӑ�X����Q��_��})�+e1�5��n��q?��[�^�9�<�z3Fsi�8�'�)9p)�{��RP�Z+�*��p(aY��V����6l�g�9��;���d�u���Nt@�3�sTwzaŇ�GT�b�H��(#��*zc�������9K�b1�����t����Ê��
�Z?g�iD���H�R���B���^M����v���O���L�D,'d�q�C�P�����$Δ��U�֟֊=�s��F�$��J�ދZ?�N��������A�N�WP��,�� �¦�&;�x��dup�����i���Ipd���;�Dž!��ֿѮAb%�u��}j��-p��>I�[�N�bi����G�'�;4w�m]H�]����#LӘNN��R��������s�.]��en��-�8e��Ps����Q��;���ț�E�ݫ���7��g�_L��W��EZ:/��I���a�g�n�ܤ��iٹ���ŷ�T���H~i�a�����֎�~KV������ A-2m]�F"�m�9-Zbǰ�״ @����~�4�N�[�Uxč�tl>������u#r�gѐ�3���;M9�<�J�����1�vfL8����1�P�HgP�Xv��������{����O�}�n��KQ؋����7<�l�fey<�}�>�bX���4<`Y7���si��V)�s�:�{�rO�h�z �@4VW�B���&�������ɡob܋�F��4>y�s�fXWS�N�O$�,.u:�ԫ��g�yao4��$h��D#��ٸf^kh�7�#1Z�֥&���*�v-��;bޭ����Q�����h�ow�y]�ه.+�7�M�ⴻ �JY��g�f�i3q��KC��3�¹�?5�Z.N��^Z w���KF͂���7��ރ۞��wj��T�J.�q��\Sv1U����R��욽&�N����pЖ`�`у��m`v�n#z��4��>e��V�`'���h�����'�j�AҔ�-�4:H���n]9�h<��n����U�6m��2c�E�1/�Y�%���I��~ʏ�|VBƟ@����;�������%�M9M���}��1�D��d����%g���O��]��у&�r��f�7�uܲ���(!1AQaq�������0� ���?!��*��@)�Je�G��j��{�['��v+���������)���(�/����д%젍Z��kk�Lu�Rm���j.c���@Z� V�J��d��j���h6���2AO�� a;oBu���H�=���nK�W8�B�ɰ�u?��бأm,�sr����|����8˨i��qI2tZ�ۄJP��XE��������zޔj~]UMu����zv!����N�&�1�Y��zJ�ՠ��\p��o'ሸ�C؊Y��TD"HM5�Ъ��i߯a���F����A)�����ڮ����z�E���@�hg�֝8�1jk��\�M�3�8ܢ�� ������s�7����N}�ޭ������GN�Bc���L pk�;�J�δ3�e�iU�gAYW]\�>�GyگQ=��f�KA;T�a`eM+Q �� �Ln���̌]GM�����<Ħ�j���H��N�M�x�}aX{̣S� ��ԅ��n�MA�S�r�(����(�L��zo9���.�;
�ӳf������`Ӕ٢3�� IW��\9~_���saa�\ԊW�ܭX:���ӆ�38�ty*����N�qP����BI�Y��jE��>DP�!�R%-��4��'�皺;��~J�!�7m���X��h�P!曭���$�\�AYj�.lC��4��+�jD�dgC0-*���|��`ZD�+л�C"��)��s��8Kq�pq���Ms��4� ��7\U`�.��[Ey8��AH!/��,���(:M -�T䓥�~O�4-���Ԓn��}HDN7���K���$�_Ԕ䚞`�R�hB�_aX?4V��ŗ�@ه�u�a�;�{PcT+�������7YBo�?��r-ͩ{�ĎA�� ����˼n��M286��G���1���V�˜Jв"l��V5���5�C]h���̊�A���%� �'p���Ԃ���Ր��9=�d�=�e�{�'<3�_ �:^�~��4�(�n�-C�s��5m![�jmIqU�~�Tw8��`���p�H8�u�Д l m�aP�0�������9y����CM��F1G糞�.�U~�������FC�{�!e(Y�:���P����7~;�L�N^{�1r�\���ԬG(���0d�ÏO�qK�Z�⑼�T�{ 2��s��Kd�Տ?mMQ��=���6�7�i�����H+����9��d��=��;�QؤH8n�Lb�D��yS%�(�{b���Cu���p�t#C���$A"�H{���jqᶯ�:�n=E����hH�`�!�m��MA������?�v6���+MԿ⟚qK�i�D�*Q5��CZ���2�|]�:Xd+�t�:o@��M��� :�32��b����[\5=�ֵ7])�|t��Ϻ����w�B�ń�e���!`�:��I,��9:����j@/a 8����+<�u�(T^ۺ~��2oE�B�%b)��z��ݳځ�)��i�j��&��Fi`qr��w���7�@��P�� �3Z&<�m�S�C����7t�T����ƴ�q~J�e�r6�Z]�rL���ه�E17'�x���+[�ܜTc6�/�����W�`�qpMJ���N5^����x�}{l�Fm������1�oZ\�����/d�/6� �uӸ�0elXuX;M��$M�}mB��������Z%e���3f�js����O�J~2�z�86�*PB��v�Ν��e-��.�/��L�O����2����9���4}|��T5M���hÐ7�F*��l+y0����:|��=k[�d�;|�ԉe�=w�<��õ�<��'!1AQaq����� ������?��5����)�(���+>v����6&{���Ǹ@����M�����v��iA 6T'�w��h�s �E}�x��G&'g�� J~1q�f�f���&��q˘���-���vYm
�/i1 �I��6��u,)�#�,����l}*&`�$�ͬe�%�w3�x�Ѥ�Xc�D��执g�峕�5B/�|$��=���%8 a��2.l� c�@G� �\�/x[өq�]�v5?�����N|�!���\��,>��{�"r�/��?��&!1QAa�� ��ᑱ����?ĊD�肭�� nv@�yޝ (�����I ����U - ���b�m�E>,��1v!�d�&�� ���&�檔�5D�&0P��Ԕ�͒@Z��:E"� Q��`>PH:~�O�����P�3W��@hM��k�U��\�O��R�������5ʄ�,��f�|��r���}јxo)�"+h�QK���/��0�`�5�{M~�� ���'!1AQaq���0 �������?�?�k��#^�~�G��#V,������#Z�1'ܤ����������~p�O%O�O�\�q�`�~��}��E�Ű5 �輸�du����x\�$���s[�{T2t`B��gq�4Z]b� 㛪�3,(@����bAp�r)9:@|b�!r�g:N�^�Ʌ��� �x_�\��pm7I��0?>^k��������w���|.K�[sF@�]Gn*L �yO� le�P�.p��֍�j�S�=�ʨ�ןQF�"��5zʼn���k�*8�u" ����Fg��� �cSy�V������Ƈ��N��ؐ(�����48hV�A�ӎ^��^ ���jyB� ��p"�����y]�ļlU�(�7�U`3�pCGF'&yg������o��z������X��ν:�P"@�G@x[��o&MJ�$F.����hi w;}�/^͇q���n�mN�/�TQ���އ��O1\,}��bQ #¯^S!)��X���#GPȏ�t�� c^\��' }iIZ���a�)��������z��4͊�Ξy��48,��f���#�����KP!Jx�|w�ʆ�������������#��Z�������< �~K��r�p&qH/;�R���沽�+�E�R���~0v���V#ʀ�T��S(-ڝ��B�y�b�C�D������b��������8��~�= �Y�ͧ]��@n����M�k2�%�;�%,�r6�LR腻?^��;KŇ=�ք ���=`�ɥ��/����z�&�I{���#J��M���C��}�H9^UJ�,P ��pS����G�d69Ϭu���%"��ˢP��K�"k)��=��9� ����㇌,��Oli��Xzh� " � ������R��^�s����N�k��Q>�63(���� ��PQ�Py�����3����$f+W՛=4�ǁ`*��^��Eb�K�t�6��^��!�籷��ȭ��K{/;�L���p�x�����;a���Oلz�[�.NP4�]Gc�T�v����~sg'LED��]j��'�G�]�6rY����UPw�*O�İՋi�'8�۴�#g�Xx+=�eU6�R��c�"�u2��~�?n�y�;�u��3�'��6�f������b��߬M�$*��k&?6���*^1n����ێz)<��Gz� �����7����Y� ��ۃ)$A��2�L6� ե�H�<�r��#ʽ2��O��R���z�A��XW��@���������<�G� Ϥ�^�˓i�M�W���6 ��0��m){c�;ݧ�>R�a����}1�ٯ%�EY2�Q��Ep���$ ��E��qS��t#+x� *�h�UI��XM?�'//��a'�G�����q@���<��z��؟����cd��z�ˬT_u�Ѯ����&�z�k ��n ]�a%�py»�`Qd�xc������n�� ��*��oTd�;'j�<�!j���'�(~�ʹW�M� P�mȘ��@֨V+��R�`�$��`�+@��_[�kG����P���Zh9�R����&5b�v���Z���#p�&�Ա+��8�etZ7G���;��@"�e0���v7����?��z�?_���_�q1�T�"�p�ˎ/U 6_�B�>��0( ��}G#������Ȣ�p�� �9��;/& `�B&$�y��t(�*z�x���Ӕ������S�?Kȏ3���{p� b � ۍ-�z܈֦��6?<���ǬP�N�G �更� �6�/h�����0Z���������i�ua��e�*M'A� �x��v�q.>�F� oN{��Q���{gD��L��u��=|���O xN���d���q�8(��E�Uu��,��O� t�DJ ����;��G����e���C��VYZ�� ���T4{����(�Ӳ'c�t�f��w�c�jr�e�m �#7,�6��B�E4Q�P�.P�(&��^{9H-�m�o ��q�g1���=��>p�)/"p0!4�mS6ú�FN���h��D �)��XdT �FؤZ⸚�k���H�c8v� <���u�P�Հ���:��_�EN��|�ӛ��u?-�/�o�Lhk�ܸ�S�;�Rī�����T"�N����M��px7<�� j�$��`�Y)Pjh 5` K�Qf�4�C�bX"�D���;HD�Z�9R b�F)�UA����v�#��HD�!{������>I� �`�ԁ i�4�)t*�ç�Le�_���>ru�GEQg��ǔct��ō0��l6v���d�� ��GG8���v^�|�#JyZPSO�� Y�CuAߐ�"�x���OfHF@�K�V�!少Eҕ]h� ��[���)��.q����*0I<8��^�6�}p��^tho���ig�i����DK���p,��2�3�I��5����쓄OY�6s7Qs�Ow^�w�J/�A➰������0������g(Մ��y��Kԇ����QS��?H���w�X�=��ҞX�~���Q=�'���p?7�@g�~�G�}�r��g�T?���
One Hat Cyber Team
One Hat Cyber Team
Your IP :
18.217.156.194
Server IP :
162.0.235.113
Server :
Linux premium146.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software :
LiteSpeed
PHP Version :
5.6.40
Buat File
|
Buat Folder
Dir :
~
/
opt
/
alt
/
ruby31
/
share
/
ruby
/
View File Name :
json.rb
#frozen_string_literal: false require 'json/common' ## # = JavaScript \Object Notation (\JSON) # # \JSON is a lightweight data-interchange format. # # A \JSON value is one of the following: # - Double-quoted text: <tt>"foo"</tt>. # - Number: +1+, +1.0+, +2.0e2+. # - Boolean: +true+, +false+. # - Null: +null+. # - \Array: an ordered list of values, enclosed by square brackets: # ["foo", 1, 1.0, 2.0e2, true, false, null] # # - \Object: a collection of name/value pairs, enclosed by curly braces; # each name is double-quoted text; # the values may be any \JSON values: # {"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null} # # A \JSON array or object may contain nested arrays, objects, and scalars # to any depth: # {"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]} # [{"foo": 0, "bar": 1}, ["baz", 2]] # # == Using \Module \JSON # # To make module \JSON available in your code, begin with: # require 'json' # # All examples here assume that this has been done. # # === Parsing \JSON # # You can parse a \String containing \JSON data using # either of two methods: # - <tt>JSON.parse(source, opts)</tt> # - <tt>JSON.parse!(source, opts)</tt> # # where # - +source+ is a Ruby object. # - +opts+ is a \Hash object containing options # that control both input allowed and output formatting. # # The difference between the two methods # is that JSON.parse! omits some checks # and may not be safe for some +source+ data; # use it only for data from trusted sources. # Use the safer method JSON.parse for less trusted sources. # # ==== Parsing \JSON Arrays # # When +source+ is a \JSON array, JSON.parse by default returns a Ruby \Array: # json = '["foo", 1, 1.0, 2.0e2, true, false, null]' # ruby = JSON.parse(json) # ruby # => ["foo", 1, 1.0, 200.0, true, false, nil] # ruby.class # => Array # # The \JSON array may contain nested arrays, objects, and scalars # to any depth: # json = '[{"foo": 0, "bar": 1}, ["baz", 2]]' # JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]] # # ==== Parsing \JSON \Objects # # When the source is a \JSON object, JSON.parse by default returns a Ruby \Hash: # json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}' # ruby = JSON.parse(json) # ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil} # ruby.class # => Hash # # The \JSON object may contain nested arrays, objects, and scalars # to any depth: # json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}' # JSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]} # # ==== Parsing \JSON Scalars # # When the source is a \JSON scalar (not an array or object), # JSON.parse returns a Ruby scalar. # # \String: # ruby = JSON.parse('"foo"') # ruby # => 'foo' # ruby.class # => String # \Integer: # ruby = JSON.parse('1') # ruby # => 1 # ruby.class # => Integer # \Float: # ruby = JSON.parse('1.0') # ruby # => 1.0 # ruby.class # => Float # ruby = JSON.parse('2.0e2') # ruby # => 200 # ruby.class # => Float # Boolean: # ruby = JSON.parse('true') # ruby # => true # ruby.class # => TrueClass # ruby = JSON.parse('false') # ruby # => false # ruby.class # => FalseClass # Null: # ruby = JSON.parse('null') # ruby # => nil # ruby.class # => NilClass # # ==== Parsing Options # # ====== Input Options # # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed; # defaults to +100+; specify +false+ to disable depth checking. # # With the default, +false+: # source = '[0, [1, [2, [3]]]]' # ruby = JSON.parse(source) # ruby # => [0, [1, [2, [3]]]] # Too deep: # # Raises JSON::NestingError (nesting of 2 is too deep): # JSON.parse(source, {max_nesting: 1}) # Bad value: # # Raises TypeError (wrong argument type Symbol (expected Fixnum)): # JSON.parse(source, {max_nesting: :foo}) # # --- # # Option +allow_nan+ (boolean) specifies whether to allow # NaN, Infinity, and MinusInfinity in +source+; # defaults to +false+. # # With the default, +false+: # # Raises JSON::ParserError (225: unexpected token at '[NaN]'): # JSON.parse('[NaN]') # # Raises JSON::ParserError (232: unexpected token at '[Infinity]'): # JSON.parse('[Infinity]') # # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'): # JSON.parse('[-Infinity]') # Allow: # source = '[NaN, Infinity, -Infinity]' # ruby = JSON.parse(source, {allow_nan: true}) # ruby # => [NaN, Infinity, -Infinity] # # ====== Output Options # # Option +symbolize_names+ (boolean) specifies whether returned \Hash keys # should be Symbols; # defaults to +false+ (use Strings). # # With the default, +false+: # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}' # ruby = JSON.parse(source) # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil} # Use Symbols: # ruby = JSON.parse(source, {symbolize_names: true}) # ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil} # # --- # # Option +object_class+ (\Class) specifies the Ruby class to be used # for each \JSON object; # defaults to \Hash. # # With the default, \Hash: # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}' # ruby = JSON.parse(source) # ruby.class # => Hash # Use class \OpenStruct: # ruby = JSON.parse(source, {object_class: OpenStruct}) # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil> # # --- # # Option +array_class+ (\Class) specifies the Ruby class to be used # for each \JSON array; # defaults to \Array. # # With the default, \Array: # source = '["foo", 1.0, true, false, null]' # ruby = JSON.parse(source) # ruby.class # => Array # Use class \Set: # ruby = JSON.parse(source, {array_class: Set}) # ruby # => #<Set: {"foo", 1.0, true, false, nil}> # # --- # # Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing. # See {\JSON Additions}[#module-JSON-label-JSON+Additions]. # # === Generating \JSON # # To generate a Ruby \String containing \JSON data, # use method <tt>JSON.generate(source, opts)</tt>, where # - +source+ is a Ruby object. # - +opts+ is a \Hash object containing options # that control both input allowed and output formatting. # # ==== Generating \JSON from Arrays # # When the source is a Ruby \Array, JSON.generate returns # a \String containing a \JSON array: # ruby = [0, 's', :foo] # json = JSON.generate(ruby) # json # => '[0,"s","foo"]' # # The Ruby \Array array may contain nested arrays, hashes, and scalars # to any depth: # ruby = [0, [1, 2], {foo: 3, bar: 4}] # json = JSON.generate(ruby) # json # => '[0,[1,2],{"foo":3,"bar":4}]' # # ==== Generating \JSON from Hashes # # When the source is a Ruby \Hash, JSON.generate returns # a \String containing a \JSON object: # ruby = {foo: 0, bar: 's', baz: :bat} # json = JSON.generate(ruby) # json # => '{"foo":0,"bar":"s","baz":"bat"}' # # The Ruby \Hash array may contain nested arrays, hashes, and scalars # to any depth: # ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad} # json = JSON.generate(ruby) # json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}' # # ==== Generating \JSON from Other Objects # # When the source is neither an \Array nor a \Hash, # the generated \JSON data depends on the class of the source. # # When the source is a Ruby \Integer or \Float, JSON.generate returns # a \String containing a \JSON number: # JSON.generate(42) # => '42' # JSON.generate(0.42) # => '0.42' # # When the source is a Ruby \String, JSON.generate returns # a \String containing a \JSON string (with double-quotes): # JSON.generate('A string') # => '"A string"' # # When the source is +true+, +false+ or +nil+, JSON.generate returns # a \String containing the corresponding \JSON token: # JSON.generate(true) # => 'true' # JSON.generate(false) # => 'false' # JSON.generate(nil) # => 'null' # # When the source is none of the above, JSON.generate returns # a \String containing a \JSON string representation of the source: # JSON.generate(:foo) # => '"foo"' # JSON.generate(Complex(0, 0)) # => '"0+0i"' # JSON.generate(Dir.new('.')) # => '"#<Dir>"' # # ==== Generating Options # # ====== Input Options # # Option +allow_nan+ (boolean) specifies whether # +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated; # defaults to +false+. # # With the default, +false+: # # Raises JSON::GeneratorError (920: NaN not allowed in JSON): # JSON.generate(JSON::NaN) # # Raises JSON::GeneratorError (917: Infinity not allowed in JSON): # JSON.generate(JSON::Infinity) # # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON): # JSON.generate(JSON::MinusInfinity) # # Allow: # ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity] # JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]' # # --- # # Option +max_nesting+ (\Integer) specifies the maximum nesting depth # in +obj+; defaults to +100+. # # With the default, +100+: # obj = [[[[[[0]]]]]] # JSON.generate(obj) # => '[[[[[[0]]]]]]' # # Too deep: # # Raises JSON::NestingError (nesting of 2 is too deep): # JSON.generate(obj, max_nesting: 2) # # ====== Output Options # # The default formatting options generate the most compact # \JSON data, all on one line and with no whitespace. # # You can use these formatting options to generate # \JSON data in a more open format, using whitespace. # See also JSON.pretty_generate. # # - Option +array_nl+ (\String) specifies a string (usually a newline) # to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>. # - Option +object_nl+ (\String) specifies a string (usually a newline) # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>. # - Option +indent+ (\String) specifies the string (usually spaces) to be # used for indentation; defaults to the empty \String, <tt>''</tt>; # defaults to the empty \String, <tt>''</tt>; # has no effect unless options +array_nl+ or +object_nl+ specify newlines. # - Option +space+ (\String) specifies a string (usually a space) to be # inserted after the colon in each \JSON object's pair; # defaults to the empty \String, <tt>''</tt>. # - Option +space_before+ (\String) specifies a string (usually a space) to be # inserted before the colon in each \JSON object's pair; # defaults to the empty \String, <tt>''</tt>. # # In this example, +obj+ is used first to generate the shortest # \JSON data (no whitespace), then again with all formatting options # specified: # # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}} # json = JSON.generate(obj) # puts 'Compact:', json # opts = { # array_nl: "\n", # object_nl: "\n", # indent: ' ', # space_before: ' ', # space: ' ' # } # puts 'Open:', JSON.generate(obj, opts) # # Output: # Compact: # {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}} # Open: # { # "foo" : [ # "bar", # "baz" # ], # "bat" : { # "bam" : 0, # "bad" : 1 # } # } # # == \JSON Additions # # When you "round trip" a non-\String object from Ruby to \JSON and back, # you have a new \String, instead of the object you began with: # ruby0 = Range.new(0, 2) # json = JSON.generate(ruby0) # json # => '0..2"' # ruby1 = JSON.parse(json) # ruby1 # => '0..2' # ruby1.class # => String # # You can use \JSON _additions_ to preserve the original object. # The addition is an extension of a ruby class, so that: # - \JSON.generate stores more information in the \JSON string. # - \JSON.parse, called with option +create_additions+, # uses that information to create a proper Ruby object. # # This example shows a \Range being generated into \JSON # and parsed back into Ruby, both without and with # the addition for \Range: # ruby = Range.new(0, 2) # # This passage does not use the addition for Range. # json0 = JSON.generate(ruby) # ruby0 = JSON.parse(json0) # # This passage uses the addition for Range. # require 'json/add/range' # json1 = JSON.generate(ruby) # ruby1 = JSON.parse(json1, create_additions: true) # # Make a nice display. # display = <<EOT # Generated JSON: # Without addition: #{json0} (#{json0.class}) # With addition: #{json1} (#{json1.class}) # Parsed JSON: # Without addition: #{ruby0.inspect} (#{ruby0.class}) # With addition: #{ruby1.inspect} (#{ruby1.class}) # EOT # puts display # # This output shows the different results: # Generated JSON: # Without addition: "0..2" (String) # With addition: {"json_class":"Range","a":[0,2,false]} (String) # Parsed JSON: # Without addition: "0..2" (String) # With addition: 0..2 (Range) # # The \JSON module includes additions for certain classes. # You can also craft custom additions. # See {Custom \JSON Additions}[#module-JSON-label-Custom+JSON+Additions]. # # === Built-in Additions # # The \JSON module includes additions for certain classes. # To use an addition, +require+ its source: # - BigDecimal: <tt>require 'json/add/bigdecimal'</tt> # - Complex: <tt>require 'json/add/complex'</tt> # - Date: <tt>require 'json/add/date'</tt> # - DateTime: <tt>require 'json/add/date_time'</tt> # - Exception: <tt>require 'json/add/exception'</tt> # - OpenStruct: <tt>require 'json/add/ostruct'</tt> # - Range: <tt>require 'json/add/range'</tt> # - Rational: <tt>require 'json/add/rational'</tt> # - Regexp: <tt>require 'json/add/regexp'</tt> # - Set: <tt>require 'json/add/set'</tt> # - Struct: <tt>require 'json/add/struct'</tt> # - Symbol: <tt>require 'json/add/symbol'</tt> # - Time: <tt>require 'json/add/time'</tt> # # To reduce punctuation clutter, the examples below # show the generated \JSON via +puts+, rather than the usual +inspect+, # # \BigDecimal: # require 'json/add/bigdecimal' # ruby0 = BigDecimal(0) # 0.0 # json = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"} # ruby1 = JSON.parse(json, create_additions: true) # 0.0 # ruby1.class # => BigDecimal # # \Complex: # require 'json/add/complex' # ruby0 = Complex(1+0i) # 1+0i # json = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0} # ruby1 = JSON.parse(json, create_additions: true) # 1+0i # ruby1.class # Complex # # \Date: # require 'json/add/date' # ruby0 = Date.today # 2020-05-02 # json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0} # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 # ruby1.class # Date # # \DateTime: # require 'json/add/date_time' # ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00 # json = JSON.generate(ruby0) # {"json_class":"DateTime","y":2020,"m":5,"d":2,"H":10,"M":38,"S":13,"of":"-5/24","sg":2299161.0} # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00 # ruby1.class # DateTime # # \Exception (and its subclasses including \RuntimeError): # require 'json/add/exception' # ruby0 = Exception.new('A message') # A message # json = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null} # ruby1 = JSON.parse(json, create_additions: true) # A message # ruby1.class # Exception # ruby0 = RuntimeError.new('Another message') # Another message # json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null} # ruby1 = JSON.parse(json, create_additions: true) # Another message # ruby1.class # RuntimeError # # \OpenStruct: # require 'json/add/ostruct' # ruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby"> # json = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}} # ruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby"> # ruby1.class # OpenStruct # # \Range: # require 'json/add/range' # ruby0 = Range.new(0, 2) # 0..2 # json = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]} # ruby1 = JSON.parse(json, create_additions: true) # 0..2 # ruby1.class # Range # # \Rational: # require 'json/add/rational' # ruby0 = Rational(1, 3) # 1/3 # json = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3} # ruby1 = JSON.parse(json, create_additions: true) # 1/3 # ruby1.class # Rational # # \Regexp: # require 'json/add/regexp' # ruby0 = Regexp.new('foo') # (?-mix:foo) # json = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"} # ruby1 = JSON.parse(json, create_additions: true) # (?-mix:foo) # ruby1.class # Regexp # # \Set: # require 'json/add/set' # ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}> # json = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]} # ruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}> # ruby1.class # Set # # \Struct: # require 'json/add/struct' # Customer = Struct.new(:name, :address) # Customer # ruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main"> # json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]} # ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main"> # ruby1.class # Customer # # \Symbol: # require 'json/add/symbol' # ruby0 = :foo # foo # json = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"} # ruby1 = JSON.parse(json, create_additions: true) # foo # ruby1.class # Symbol # # \Time: # require 'json/add/time' # ruby0 = Time.now # 2020-05-02 11:28:26 -0500 # json = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000} # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500 # ruby1.class # Time # # # === Custom \JSON Additions # # In addition to the \JSON additions provided, # you can craft \JSON additions of your own, # either for Ruby built-in classes or for user-defined classes. # # Here's a user-defined class +Foo+: # class Foo # attr_accessor :bar, :baz # def initialize(bar, baz) # self.bar = bar # self.baz = baz # end # end # # Here's the \JSON addition for it: # # Extend class Foo with JSON addition. # class Foo # # Serialize Foo object with its class name and arguments # def to_json(*args) # { # JSON.create_id => self.class.name, # 'a' => [ bar, baz ] # }.to_json(*args) # end # # Deserialize JSON string by constructing new Foo object with arguments. # def self.json_create(object) # new(*object['a']) # end # end # # Demonstration: # require 'json' # # This Foo object has no custom addition. # foo0 = Foo.new(0, 1) # json0 = JSON.generate(foo0) # obj0 = JSON.parse(json0) # # Lood the custom addition. # require_relative 'foo_addition' # # This foo has the custom addition. # foo1 = Foo.new(0, 1) # json1 = JSON.generate(foo1) # obj1 = JSON.parse(json1, create_additions: true) # # Make a nice display. # display = <<EOT # Generated JSON: # Without custom addition: #{json0} (#{json0.class}) # With custom addition: #{json1} (#{json1.class}) # Parsed JSON: # Without custom addition: #{obj0.inspect} (#{obj0.class}) # With custom addition: #{obj1.inspect} (#{obj1.class}) # EOT # puts display # # Output: # # Generated JSON: # Without custom addition: "#<Foo:0x0000000006534e80>" (String) # With custom addition: {"json_class":"Foo","a":[0,1]} (String) # Parsed JSON: # Without custom addition: "#<Foo:0x0000000006534e80>" (String) # With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo) # module JSON require 'json/version' begin require 'json/ext' rescue LoadError require 'json/pure' end end