In CSV file, I have the following line :
data1;data2;{"key1":"value1","key2":"value2"}
I can parse it and get my ruby hash like this :
require 'csv'
line = 'data1;data2;{"key1":"value1","key2":"value2"}'
csv = CSV.parse_line(line, col_sep: ";", quote_char: "\x00")
=> ["data1", "data2", "{\"key1\":\"val", "ue1\",\"key2\":\"value2\"}"]
JSON.parse(csv[2])
But... it fails when a value includes seperator character (;
), because it is interpreted
require 'csv'
line = 'data1;data2;{"key1":"val;ue1","key2":"value2"}'
csv = CSV.parse_line(line, col_sep: ";", quote_char: "\x00")
=> ["data1", "data2", "{\"key1\":\"val", "ue1\",\"key2\":\"value2\"}"]
# Of course
JSON.parse(csv[2])
JSON::ParserError: 784: unexpected token at '{"key1":"val'
Any idea how to deal with it ? Thanks