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

618
Views
Ruby/Rails convierte la cadena a JSON -> JSON.parse produce JSON::ParserError

Uno de los campos en mi tabla tiene el tipo JSON, por lo que dentro del modelo para guardar la cadena, necesito hacer algo como:

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

para mostrar esto en la vista, JSON.parse analiza la columna de modifications , lo que me da el error 784: unexpected token at '"test registrant history"'

Larga historia corta:

 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"'

¿Por qué está pasando esto? ¿Cómo haces JSON a partir de una cadena entonces?

[Editar]

Estoy en Rails 5 y Ruby 2.4.5

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es un problema en las versiones de json gem (<2). Para evitarlo, debe usar versiones de json> 2. Entonces, puede intentar actualizar su versión de Rails o simplemente usar quirks_mode: true .

 JSON.parse(json_test, quirks_mode: true)

Aquí hay un enlace al problema en el problema de github json

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!