---
title: "New liberal_parsing option for parsing bad CSV data"
description:
  "CSV input with unescaped double quotes can now be parsed in Ruby 2.4 using
  liberal_parsing option"
canonical_url: "https://www.bigbinary.com/blog/ruby-2-4-introduces-liberal_parsing-option-for-parsing-bad-csv-data"
markdown_url: "https://www.bigbinary.com/blog/ruby-2-4-introduces-liberal_parsing-option-for-parsing-bad-csv-data.md"
---

# New liberal_parsing option for parsing bad CSV data

CSV input with unescaped double quotes can now be parsed in Ruby 2.4 using
liberal_parsing option

- Author: Ershad Kunnakkadan
- Published: November 22, 2016
- Categories: Ruby 2.4, Ruby

Comma-Separated Values (CSV) is a widely used data format and almost every
language has a module to parse it. In Ruby, we have
[CSV class](http://ruby-doc.org/stdlib-2.3.2/libdoc/csv/rdoc/CSV.html) to do
that.

According to [RFC 4180](https://tools.ietf.org/html/rfc4180#page-4), we cannot
have unescaped double quotes in CSV input since such data can't be parsed.

We get `MalformedCSVError` error when the CSV data does not conform to RFC 4180.

Ruby 2.4 has added a
[liberal parsing option](https://bugs.ruby-lang.org/issues/11839) to parse such
bad data. When it is set to `true`, Ruby will try to parse the data even when
the data does not conform to RFC 4180.

```ruby

# Before Ruby 2.4

> CSV.parse_line('one,two",three,four')

CSV::MalformedCSVError: Illegal quoting in line 1.


# With Ruby 2.4

> CSV.parse_line('one,two",three,four', liberal_parsing: true)

=> ["one", "two\"", "three", "four"]

```

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2-4-introduces-liberal_parsing-option-for-parsing-bad-csv-data)
