Class: JSON::Fragment
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Struct
|
|
Instance Chain:
self,
::Struct
|
|
Inherits: | Struct |
Defined in: | ext/json/lib/json/common.rb |
Overview
Fragment
of ::JSON
document that is to be included as is:
fragment = JSON::Fragment.new("[1, 2, 3]")
JSON.generate({ count: 3, items: fragments })
This allows to easily assemble multiple ::JSON
fragments that have been persisted somewhere without having to parse them nor resorting to string interpolation.
Note: no validation is performed on the provided string. It is the responsability of the caller to ensure the string contains valid ::JSON
.
Class Method Summary
Instance Attribute Summary
Instance Method Summary
::Struct
- Inherited
#as_json | Methods |
#to_json | Returns a |
Constructor Details
.new(json) ⇒ Fragment
Instance Attribute Details
#json (rw)
Fragment
of ::JSON
document that is to be included as is:
fragment = JSON::Fragment.new("[1, 2, 3]")
JSON.generate({ count: 3, items: fragments })
This allows to easily assemble multiple ::JSON
fragments that have been persisted somewhere without having to parse them nor resorting to string interpolation.
Note: no validation is performed on the provided string. It is the responsability of the caller to ensure the string contains valid ::JSON
.