Format of compressed JSON

Dec 30, 2011 at 12:33pm

Format of compressed JSON

Is the “copy compressed” format documented anywhere or does anyone have a conversion function that produces the original JSON that they’d be willing to share? It doesn’t look like a standard zip format unless it has also been b64 encoded as well.

I’d like to look at converting posted patches into a visual view (as an experimental but possibly useful project to test some interesting languages that generate JavaScript as their target)

#60925
Jan 5, 2012 at 10:16pm

Anyone?

#219381
Jan 6, 2012 at 7:48am

Why not use Max to convert?

#219382
Jan 6, 2012 at 11:31am

The idea was to be able to get a graphic view of a patch that has been posted to the forum so that when someone is reading a post with their web browser, there could be some JavaScript that could convert that compressed patch into a visual view on the fly without having to first paste it into Max, which might not be even be available. For example, I read most of thee posts from an iPad.

I had suggested this at the Brooklyn conference.

#219383
Jan 6, 2012 at 7:01pm

I’d love to see this eventually. Even if it wasn’t a working patch, I’d love to be able to view patches on a mobile device.

You should ask if the good people of Cycling74 would include the dict.serialize example in their Max 6 SDK so you can figure out how to decompress JSON.

#219384
Jan 6, 2012 at 8:26pm

Hi dhj,

Our compressed JSON uses a non-standard variation of base64 encoded gzip’ed JSON. Your question is timely as you may have noticed that our forum compressed patch now reports the version number of the patch. It does this by decoding, decompressing, and searching through the JSON.

We aren’t going to put a lot of efforts into supporting this code, but I include for your reference and experimentation the relevant code excerpts from our forum web page (view source).

var codeGZ64 = $(this).text();
var togglename = this.id.replace(“pastedcode”, “toggle”);
var patchout = '———–end_max5_patcher———–';
// we need to cut out the begin and end patcher text
// however, since the base64 encoding of JUCE puts on an additional
// number and “.” at the beginning AND we need to cut this off, we
// will search here for the first period and not the 'begin_max5_patcher' text
var inpos = codeGZ64.indexOf(“.”);
var outpos = codeGZ64.search(patchout);
codeGZ64 = codeGZ64.slice( inpos+1, outpos);
try {
// the b64 decode algo inside of JXG will try to clean up the string, removing
// all white chars and other chars that are not part of our codex.
var code = JXG.decompress( codeGZ64 );
// let's check the code to see if it contains any max6 objs
// we will also check for any patcher objs with version info
// if so, lets update the patcher text
var obj = JSON.parse(code);
var max_version = getMaxVersion(obj);
$(“#” + togglename + ” #maxversion” ).text(max_version);
// uncomment to see the JSON above the gzip'ed code
//$(this).text( code + “n” + codeGZ64);

} catch (err) {
//alert(“could not decompress pasted Max patch code. Error: ” + err);
$(“#” + togglename + ” #maxversion” ).text(“5″);
}

We have a variety of ideas of what this opens to the door to, including what you mention for previewing patchers, searching patchers, data-mining for auto-tagging, etc. We have no commitments to what or when any additional forum patcher features might be coming, so I would encourage you to have fun with this stuff.

Keep in mind after this, you’re basically on your own, but I think it should give you enough to get access to the uncompressed JSON within a browser.

Cheers,
Joshua

This post seems to contain a broken pasted patch. This can happen if you don’t copy the entire “———-begin_max5_patcher———-” or “———–end_max5_patcher———–” for each and every patch you paste; perhaps you missed a preceding or trailing “-” when you copied the patch? Please notify the Cycling 74 web team if you think it is a bug.

#219385
Jan 6, 2012 at 8:48pm

Very cool — thanks — as I find time, I’d like to play around with this — good excuse to get up to speed with JavaScript

#219386
Jan 7, 2012 at 6:15pm

I’m up for some of this too, been looking in to it for a while, lots of cool stuff that could be done!

#219387

You must be logged in to reply to this topic.