Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:48:48+00:00 2026-06-13T06:48:48+00:00

I have a a JSON-encoded Array which looks like this (note: this is in

  • 0

I have a a JSON-encoded Array which looks like this (note: this is in a file, not the contents of a string): ["Company\\","NN","Company\\"]. Is this invalid JSON? It contains an escaped \ character and looks right to me. However:

a = '["Company\\","NN","Company\\"]'
 => "[\"Company\\\",\"NN\",\"Company\\\"]" 
JSON.parse a
JSON::ParserError: 387: unexpected token at 'NN","Company\"]'
from /Users/nneubauer/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/json/common.rb:148:in `parse'
from /Users/nneubauer/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/json/common.rb:148:in `parse'
from (irb):11
from /Users/nneubauer/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'

Interestingly:

puts a
["Company\","NN","Company\"]

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:48:49+00:00Added an answer on June 13, 2026 at 6:48 am

    I think there’s a difference between reading that sequence of bytes from a file, and putting it in your Ruby code literally.

    When you use ' as the string delimiter in Ruby code, it still interprets \\ as an escape sequence. So you get a string with the value of ["Company\","NN","Company\"].

    Then the JSON parser gets it. It sees the starting [, and then looks for a string. It interprets the \" sequence as an escape, so the first string it sees has a value of Company\",. It then expects to see a comma – but sees NN instead and throws up:

    1.9.3-p194 :009 > a = '["Company\\","NN","Company\\"]'
     => "[\"Company\\\",\"NN\",\"Company\\\"]" 
    1.9.3-p194 :010 > puts a
    ["Company\","NN","Company\"]
     => nil 
    1.9.3-p194 :011 > JSON.parse(a)
    JSON::ParserError: 387: unexpected token at 'NN","Company\"]'
    

    But if I read that byte sequence from a file using gets, then the value ends up being ["Company\\","NN","Company\\"]. This can be parsed as JSON – the \\ is interpreted by JSON, then it sees the " and closes the first string in the array properly.

    1.9.3-p194 :012 > b = gets
    ["Company\\","NN","Company\\"]
     => "[\"Company\\\\\",\"NN\",\"Company\\\\\"]\n" 
    1.9.3-p194 :013 > puts b
    ["Company\\","NN","Company\\"]
     => nil 
    1.9.3-p194 :014 > JSON.parse b
     => ["Company\\", "NN", "Company\\"] 
    1.9.3-p194 :015 > JSON.parse(b).length
     => 3 
    

    So, what are you doing wrong? Cutting and pasting from a data file into source code. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JSON string, which was an Objective C array then encoded
I have a json array in my Particles controller that looks like this after
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
I have a json array which is holding the correct string independent of language
I have an array in the database and it looks like this: {hello:world, Test:[hello]}
i have a php function which returns a random json encoded color <?php function
I have JSON like this: { something: http://something.com } and HTML like this: <a
I have this array which is retrieved by a json_encode().When I execute $.getJSON('beta.php' ,
I have an array like this: Array ( [utm_source] => website [utm_medium] => fbshare

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.