summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/json_tree.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/psych/lib/psych/visitors/json_tree.rb')
-rw-r--r--ext/psych/lib/psych/visitors/json_tree.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/ext/psych/lib/psych/visitors/json_tree.rb b/ext/psych/lib/psych/visitors/json_tree.rb
new file mode 100644
index 0000000000..0440dc778d
--- /dev/null
+++ b/ext/psych/lib/psych/visitors/json_tree.rb
@@ -0,0 +1,37 @@
+module Psych
+ module Visitors
+ class JSONTree < YAMLTree
+ def visit_Symbol o
+ append create_scalar o.to_s
+ end
+
+ def visit_NilClass o
+ scalar = Nodes::Scalar.new(
+ 'null', nil, nil, true, false, Nodes::Scalar::PLAIN)
+ append scalar
+ end
+
+ private
+ def create_document
+ doc = super
+ doc.implicit = true
+ doc.implicit_end = true
+ doc
+ end
+
+ def create_mapping
+ map = super
+ map.style = Nodes::Mapping::FLOW
+ map
+ end
+
+ def create_scalar value, anchor = nil, tag = nil, plain = false, quoted = true, style = Nodes::Scalar::ANY
+ super(value, anchor, tag, false, true, style)
+ end
+
+ def create_sequence anchor = nil, tag = nil, implicit = true, style = Nodes::Sequence::FLOW
+ super
+ end
+ end
+ end
+end