Contents

Roo

JSON.parse()

Parses JSON into a usable Roo data structure.

JSON.parse(what as Text) as Array or Hash or Nothing

Parameters

  • what: Text object. The JSON string to parse

Returns

  • If what is not vsalid JSON then returns Nothing otherwise returns either an Array or a Hash

Example

var array = '["Helen",{"name":"Elastigirl","husband":"Bob"}]'
JSON.parse(array) # ["Helen", "{"name" => "Elastigirl", "husband" => "Bob"}"]

var hash = '{"name":"Bob","wife":{"name":"Helen","alter ego":"Elastigirl"}}'
JSON.parse(hash) # {"name" => "Bob", "wife" => {"alter ego" => "Elastigirl", "name" => "Helen"}}

var invalid = '{"name": "'
JSON.parse(invalid) # Nothing