5

I'm using SJCL, and it works fine with small ASCII strings.

But when I try to decode this piece of JSON (the result of the encryption of an HTML page) I get a "this is not JSON!" error.

The JSON has been produced by SJCL, and while I did encode it and decode it using LZW and base64 I don't get this error for small strings with the same workflow.

I tracked the error message origin to the decode function. I assume the regexes are failing but I don't understand why as this seems to be a perfectly formed JSON string to me.

However, I can be wrong as if I do a JavaScript eval on it it fails on a syntax error. But if I dump it in a file Python parse it fine.

Bite code
  • 578,959
  • 113
  • 301
  • 329
  • That link to SJCL is broken. http://crypto.stanford.edu/SJCL/ I have no idea what SJCL is, I thought it was a typo for `JCL` when I saw the tag. This is the first instance of an SJCL tagged question on SO, by the way! – Ellie Kesselman Apr 30 '12 at 21:07
  • I just saw `Analysis of the Python tag Stackoverflow activity` - yɛlɛman http://yeleman.com/analyse-of-the-python-tag-stackoverflow-activity/ presume it to be yours. It is rather awesome! – Ellie Kesselman Apr 30 '12 at 21:11
  • Thanks, Yes it is my article :-) I also ported some SO answers about metaclass, decorators et yield to my website. But I fail to update it as much as I'd like to. – Bite code May 01 '12 at 05:03
  • @feral ok I fixed the link to sjcl. It's a javascript implementation of an encryption framework. It's pretty fast while not very big in size. – Bite code May 01 '12 at 05:07
  • e-sat Cool! Thank you. I just hailed the CHorror, enclosed a link to your Giant Python post. It needs to be seen. The spinning gray circle thingy was an especially nice bit of finesse. – Ellie Kesselman May 01 '12 at 05:20
  • Arg, I'm not just my little wordpress website would survive if 1% of the readers of CHorror clic on the linK. But thanks for the gesture. – Bite code May 01 '12 at 05:51

2 Answers2

4

The json that is at your this piece of json link starts and ends with a double-quote character. Is that actually part of the contents of the json? If it is, I believe that is your problem. Otherwise, it looks like valid json to me.

Sean Mickey
  • 7,618
  • 2
  • 32
  • 58
  • agreed - I took your snippet, replaced the outer " with ', stuffed it into a variable in firebug, and used jQuery.parseJSON() on it. Worked fine. – Mikeb Apr 26 '12 at 12:58
  • Not, the double quote are not part of the json. I paste the string representation in the ghist. – Bite code Apr 26 '12 at 12:59
  • Ok I removed the quotes to avoid the misenderstanding. But I'm betting now somebody will thell me this is not json but a javascript object :-) – Bite code Apr 26 '12 at 13:06
  • In my case I needed to `JSON.parse` first and then `JSON.stringify` –  Feb 09 '20 at 01:39
0

Ok I made a double passed base64 encoding. One before encryption, and one after. It seems that removing the first pass make it work.

Bite code
  • 578,959
  • 113
  • 301
  • 329