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

622
Visualizações
Ruby/Rails convert string to JSON -> JSON.parse produces JSON::ParserError

One of the fields in my table has the JSON type so inside the model to save string there I need to do something like:

create(modifications: string.to_json,
       ...
     )

to display this on the view the modifications column is parsed by JSON.parse which gives me the error 784: unexpected token at '"test registrant history"'

Long story short:

2.4.5 :042 > json_test = 'testing the string'.to_json
 => "\"testing the string\""
2.4.5 :043 > JSON.parse(json_test)
JSON::ParserError: 784: unexpected token at '"testing the string"'

why is this happening? how do you make JSON from a string then?

[Edit]

I'm on Rails 5 and Ruby 2.4.5

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's an issue on versions of json gem (<2). To avoid it you should use versions of json >2. So you might try to upgrade your rails version or just use quirks_mode: true.

JSON.parse(json_test, quirks_mode: true)

Here is a link to the issue on github json issue

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