1

I want to parse Rails production.log files and recreate the params Hash. I am stuck with the Marshal.load method, which actually expects the data to be marshalled. Well, the data is well-formed but it is a String and not in a Marshal expected format.

here is the String that i regexed out of the request from the logfile:

{
 "location"=>{"city"=>"München \"foo \" bar", "id"=>"462", "youtube_tags"=>""},
 "authenticity_token"=>"UHi0GCNDBPN/Ms+0bqEOl4HGvUjDRw8tNvtqVl3v0dY=",
 "utf8"=>"\342\234\223", "textinput"=>""
}

I tried my way around this issue with

o=JSON.parse.gsub("=>",":"))

in which case i get problems with umlauts.

Is there no way to parse or load a Hash representation from a String to actual Ruby Hash structures with Ruby 1.8.7?

z3cko
  • 3,054
  • 8
  • 40
  • 59
  • i updated the example with escaped quotes, so the problem becomes visible - eval would not parse this correctly. – z3cko Oct 13 '11 at 03:03

1 Answers1

1

This probably isn't the best way to do it, but ...

h = eval '{
            "location"=>{"city"=>"München", "id"=>"462", "youtube_tags"=>""},
            "authenticity_token"=>"UHi0GCNDBPN/Ms+0bqEOl4HGvUjDRw8tNvtqVl3v0dY=",
            "utf8"=>"\342\234\223", "textinput"=>""
          }'
mportiz08
  • 10,206
  • 12
  • 40
  • 42
  • thanks for the answer. of course eval works in this example -- but unfortunately there are lots of escaped quotes, so eval breaks immediately. any ideas? – z3cko Oct 13 '11 at 03:01