Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON.parse error, won't parse something I just JSON.stringify'd
    primarykey
    data
    text
    <p>So I have this really large object that I use to control things in a nodejs app. Occasionally I store this object in a database [mysql] so if the process crashes or gets restarted and something's been changed, the changes will be saved. Pretty simple. </p> <p>The object is this: <a href="http://snippi.com/s/z5nq0v5" rel="nofollow">http://snippi.com/s/z5nq0v5</a></p> <p>it's defined as global.config.</p> <p>So to store, I use my save function:</p> <pre><code> client.query('SELECT data FROM settings WHERE (id = \''+ config.room +'\')', function(a, b, c) { if (!b[0]) { client.query('INSERT INTO settings (id, data) VALUES (?, ?)', [config.room, JSON.stringify(config)], function (a) { if (a) throw a;Log("Saved settings"); } ); } else { client.query('UPDATE settings SET data="?" WHERE id="'+config.room+'"', [JSON.stringify(config)], function (a) { if (a) throw a;Log("Saved settings"); } ); } } ); </code></pre> <p>and that seems to work. However, when I try to load it after I change something, and it saves, I get an error. This is the loading code:</p> <pre><code> client.query('SELECT data FROM settings WHERE (id = \''+ config.room +'\')', function(a, b, c) { console.log(b.length); if (a) return console.log(a); if (!b[0]) return db.save("settings"); console.log(b[0].data); config = JSON.parse(b[0].data); Log("Loaded Settings"); } ); </code></pre> <p>As you can see, all I'm really doing is calling JSON.parse() of the object I just stringified earlier. Yet I'm getting an error. The error is </p> <pre><code>undefined:1 3Th0seB310W","ui ^ SyntaxError: Unexpected token ' </code></pre> <p>but there isn't a ' in the area where it's talking about. If you refer to the object up there.</p> <p>These are the results form console.log(b[0].data): <a href="http://snippi.com/s/tknlgyo" rel="nofollow">http://snippi.com/s/tknlgyo</a></p> <p>Any help would be appreciated, and I'll add more info if it's needed. Note: the auth code has obviously been changed, but it's just a hex value like the uid below it, just longer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload