Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

711
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda