JSON and Firefox sessionstore.js

S

Steven D'Aprano

Unless I'm badly mistaken, the Firefox sessionstore.js file is supposed
to be JSON.

In Python 3.0, I do this:
Traceback (most recent call last):
File "/usr/local/lib/python3.0/json/decoder.py", line 340, in raw_decode
obj, end = next(self._scanner.iterscan(s, **kw))
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/json/__init__.py", line 267, in load
parse_constant=parse_constant, **kw)
File "/usr/local/lib/python3.0/json/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.0/json/decoder.py", line 323, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.0/json/decoder.py", line 342, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded


Am I doing something wrong? Am I mistaken about sessionstore.js being
JSON? Is there a bug in json?

If it matters, I'm using Firefox 2.0.0.5 under Linux.
 
M

MRAB

Steven said:
Unless I'm badly mistaken, the Firefox sessionstore.js file is supposed
to be JSON.

In Python 3.0, I do this:

Traceback (most recent call last):
File "/usr/local/lib/python3.0/json/decoder.py", line 340, in raw_decode
obj, end = next(self._scanner.iterscan(s, **kw))
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/json/__init__.py", line 267, in load
parse_constant=parse_constant, **kw)
File "/usr/local/lib/python3.0/json/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.0/json/decoder.py", line 323, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.0/json/decoder.py", line 342, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded


Am I doing something wrong? Am I mistaken about sessionstore.js being
JSON? Is there a bug in json?

If it matters, I'm using Firefox 2.0.0.5 under Linux.
As far as I'm aware, the ".js" extension indicates a JavaScript file.

Is there a specific extension for JSON?

[Checks Google...]

Ah, the extension for JSON is ".json". Makes sense! :)
 
S

Steven D'Aprano

The json files are used for bookmark backups in FF 3.0 series.

That's nice to know, but I'm afraid it's irrelevant to my question. There
are lots of things which are JSON. Just because *something else* is JSON
does not imply that sessionstore.js is, or isn't, some other format.

The Mozilla knowledge base claims that sessionstore.js is JSON:

http://kb.mozillazine.org/Sessionstore.js

So does this tutorial:

https://developer.mozilla.org/En/Firefox_addons_developer_guide/
Let's_build_a_Firefox_extension


but Some Random Guy On The Internet claims it isn't:

http://broadcast.oreilly.com/2009/01/recovering-text-areas-from-fir.html


I'm leaning towards this being a bug in the json module. Unless somebody
can point me at a credible source that sessionstore.js isn't JSON, I will
report this as a bug.
 
S

Steven D'Aprano

For something with at least a vague air of credibility to it, somebody
who appears to be a Mozilla developer comments on their bug tracker,
that sessionstore.js isn't "pure JSON" (though he only identifies the
parantheses, which are much easier to fix, as being a problem):

https://bugzilla.mozilla.org/show_bug.cgi?id=407110#c2

Ah, fantastic! Or rather, damn, I was hoping it was proper JSON and not
some sort of bizarre mutant.

For what it's worth, removing the leading/trailing parentheses gives a
different error:
import io
import json
filename = '.mozilla/firefox/2z5po7dx.default/sessionstore.js'
text = open(filename).read()
text = io.StringIO(text[1:-1])
x = json.load(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/json/__init__.py", line 267, in load
parse_constant=parse_constant, **kw)
File "/usr/local/lib/python3.0/json/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.0/json/decoder.py", line 323, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.0/json/decoder.py", line 340, in raw_decode
obj, end = next(self._scanner.iterscan(s, **kw))
File "/usr/local/lib/python3.0/json/scanner.py", line 55, in iterscan
rval, next_pos = action(m, context)
File "/usr/local/lib/python3.0/json/decoder.py", line 175, in JSONObject
raise ValueError(errmsg("Expecting property name", s, end))
ValueError: Expecting property name: line 1 column 1 (char 1)


Presumably that's the error you get when you don't quote your property
names properly.
 
J

John Machin

The Mozilla knowledge base claims that sessionstore.js is JSON:

http://kb.mozillazine.org/Sessionstore.js

The claim is incorrect.
So does this tutorial:

https://developer.mozilla.org/En/Firefox_addons_developer_guide/
Let's_build_a_Firefox_extension

The claim is incorrect.
but Some Random Guy On The Internet claims it isn't:

Uche Ogbuji is scarcely "Some Random Guy On The Internet".

Moreover, his claim is correct.
I'm leaning towards this being a bug in the json module. Unless somebody
can point me at a credible source that sessionstore.js isn't JSON,

http://www.json.org/ ... check the syntax. No mention of parentheses
as being special. No mention of unquoted property names.
I will
report this as a bug.

I suggest that you restrict your report to the kludgy double-exception
that you observed with Python 3.X. Python 2.6.2 produces an
unexceptional exception :)

HTH,
John
 
Ð

Дамјан ГеоргиевÑки

Unless I'm badly mistaken, the Firefox sessionstore.js file is
supposed to be JSON. ....
If it matters, I'm using Firefox 2.0.0.5 under Linux.

maybe it can be parsed with PyYAML?


--
дамјан ( http://softver.org.mk/damjan/ )

Well when _I_ was in school, I had to run Netscape on HP/UX, displayed on my
local X Server running on a Windows 3.1 box. Displayed over a 2400 baud
modem. Uphill. Both ways. In the rain. With NOBODY to hold my hands. Because
the life of the geek is a lonely life.
- aclarke on /.
 
M

Matt Nordhoff

Steven said:
Ah, fantastic! Or rather, damn, I was hoping it was proper JSON and not
some sort of bizarre mutant.

For what it's worth, removing the leading/trailing parentheses gives a
different error:

Presumably that's the error you get when you don't quote your property
names properly.

That bug is about changing it *to* JSON-plus-parentheses. The patch
landed [1] (and was subsequently backed out [2] and landed again [3]) in
time for Firefox 3.5, but unless you're running that, it's still
JavaScript source code, generated by toSource() [4]:

<http://hg.mozilla.org/mozilla-centr...ents/sessionstore/src/nsSessionStore.js#l2221>
(<http://xrl.us/beqbpo>)

[1] <http://hg.mozilla.org/mozilla-central/rev/10c21d116e5d>
[2] <http://hg.mozilla.org/mozilla-central/rev/04c360f123e5>
[3] <http://hg.mozilla.org/mozilla-central/rev/22074494eef3>
[4]
<https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Function/ToSource>
(<http://xrl.us/beqbo7>)
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,034
Messages
2,570,356
Members
47,002
Latest member
RobertoLip

Latest Threads

Top