Method: JSONX.convert
- Defined in:
- lib/json/next/parser/jsonx.rb
.convert(text) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/json/next/parser/jsonx.rb', line 68 def self.convert( text ) ## pass 1: remove/strip comments text = strip_comments( text ) ## pass 2: requote/normalize quotes text = normalize_quotes( text ) ## pass 3: quote unquoted and remove trailing commas text = text.gsub( /#{KEYWORDS}|#{IDENTIFIER}|#{DOUBLE_QUOTE}|#{TRAILING_COMMA}/ox ) do |match| ## puts "match: >>#{match}<< : #{match.class.name}" m = Regexp.last_match if m[:identifier] ## puts "!!! identfier -- wrap in double quotes" '"' + m[:identifier] + '"' elsif m[:trailing_comma] ## puts "!!! trailing comma -- remove" '' else match end end ## pass 4 - auto-add (missing optional) commas text = JSON::Next::Commata.convert( text ) text end |