0

I have a program that can deliver its reports to a variety of destinations including flat files, elasticsearch DB and our call management system.

I have a set to Dest classes which attend to the details of getting the data into the right format for the intended destination. Not surprisingly, the ES one uses a puts.item.to_json to deliver its output (where item is a hash)

The problem is that some hashes are printed as "{\"key\":\"value\"}" and others print 'correctly' i.e without the ". I know that the output from to_json has the escapes in the output so that it produces the expected result with puts but in my case this works just some of the time.

Coping with the two types of behaviour is painful!

Any ideas what is going on?

Russell Fulton
  • 570
  • 4
  • 17
  • Hey Russell, looks like you can use the `.stringify()` method to help out your cause. Here is a link to an answer that will hopefully give you a good explanation and help you solve your problem.(https://stackoverflow.com/questions/4253367/how-to-escape-a-json-string-containing-newline-characters-using-javascript) – kparekh01 Jul 10 '17 at 23:20
  • Sounds like something is JSON encoding twice. First the object results in a string, then the string is encoded. – Chet Jul 10 '17 at 23:20
  • Chet is bang on. That is exactly what happened. Happy to accept that as the answer. – Russell Fulton Jul 11 '17 at 03:04

0 Answers0