Skip to content

Instantly share code, notes, and snippets.

@adamyanalunas
Last active December 18, 2015 01:59
Show Gist options
  • Save adamyanalunas/5708195 to your computer and use it in GitHub Desktop.
Save adamyanalunas/5708195 to your computer and use it in GitHub Desktop.
Making real JSON from Mixpanel's dump API.
var takeDump = function(foo, bar, body) {
// The "body" is the raw response from https://data.mixpanel.com API
// At this point there are line returns (\n) separating each event and the list of events is not wrapped in an array literal ([])
// Take out line returns and replace with proper comma separators
var tight = body.replace(/[\n\r\t]/g, ',');
// To return a list you've got to wrap it in an array
// There's a trailing newline returned, hence the substring snip
var wrapped = '[' + tight.substring(0, tight.length-1) + ']';
// Finally it can be parsed a real JSON
var properJSON = JSON.parse(wrapped);
return properJSON;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment