Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

709
Views
How to escape single quotes in json string? JSON::ParserError Ruby

I'm getting /json/common.rb:156:in `parse': 783: unexpected token at '' (JSON::ParserError) while trying to parse a json file in ruby. The problem was because there were some single quotes in one of the strings:

parsed = JSON.parse("{
  \"key1\":\"value1\",
  \"key2\":\"value2\",
  \"key3\":12345,
  \"key4\":\"''value4''\",
  }")

Is there a way to escape the single quotes in the strings without affect words like don't? The json is read from a file using JSON.parse(file.get_input_stream.read) that's why there are \.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The single quotes aren't your problem, your problem is that you have a stray trailing comma:

parsed = JSON.parse("{
  \"key1\":\"value1\",
  \"key2\":\"value2\",
  \"key3\":12345,
  \"key4\":\"''value4''\",
}") #--------------------^ This should not be there.

JSON doesn't allow that comma so you don't actually have a JSON file.

You should figure out where the file came from and fix that tool to produce real JSON rather than the "looks mostly like JSON" that is currently being written to the file.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!