Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the create_additions option do in JSON.parse

Tags:

json

ruby

I came across the create_additions option in rubys JSON.parse docs but I can't seem to find any documentation about it.

The rdoc describes the option with:

create_additions: If set to false, the Parser doesn't create additions even if a matching class and ::create_id was found. This option defaults to true.

Out of curiosity, can anyone explain what this option actually does and what this "additions" feature of JSON.parse is anyways?

like image 927
Pascal Avatar asked Nov 13 '12 13:11

Pascal


People also ask

What does JSON parse() method do?

The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.

What does JSON parse mean?

JSON parsing is the process of converting a JSON object in text format to a Javascript object that can be used inside a program. In Javascript, the standard way to do this is by using the method JSON.

How to parse the JSON data in JavaScript?

Use the JavaScript function JSON.parse() to convert text into a JavaScript object: const obj = JSON.parse('{"name":"John", "age":30, "city":"New York"}'); Make sure the text is in JSON format, or else you will get a syntax error.

What does JSON parse in Ruby do?

Once we have the file loaded, we can parse the JSON data using the JSON. parse method. This method will create a Ruby hash with the JSON keys. Once loaded, we can proceed to work with the data like an ordinary Ruby hash.


1 Answers

The "additions" are additions to pure JSON. If a hash has the json_class key (customizable with JSON.create_id), it is deserialized as that class instead of a plain hash.

like image 80
Martin Vidner Avatar answered Sep 20 '22 23:09

Martin Vidner