2

I am trying to use req library to crawl a page. The response for the page, is almost a JSON object, except for the keys being unquoted.

Is it possible to use Aeson to do relaxed parsing of it?

What could be the simplest hack that I can do with req to do that.

I tried to do regex replace in bytestring to introduce quotes, but it gets enormously complicated soon.

duplode
  • 33,731
  • 7
  • 79
  • 150
  • 2
    Is filing a bug report to get a valid JSON response an option? – chepner Apr 02 '19 at 13:29
  • It may be easier to write your own parser. Perhaps take a copy of the Aeson parser and make the changes to it -- you now have something you can work with. – Bob Dalgleish Apr 02 '19 at 13:30
  • 5
    You might be able to pre-process the response with [`jq`](https://stedolan.github.io/jq/); treat the response as a filter: `bad_json='{foo: "bar"}'; jq -n "$bad_json"` will output `{"foo": "bar"}`. – chepner Apr 02 '19 at 13:31
  • @chepner I don't think its possible. Its not even a documented API. I think writing my own parser is the only way to go about this I think. – Vinothkumar Raman Apr 02 '19 at 13:45
  • There might be value in having a permissive parsing mode in `aeson` that handled various types of malformed input. So if you extended `aeson` it might result in a patch that could be upstreamed – jberryman Apr 02 '19 at 15:50

0 Answers0