Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

713
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda