Last active
December 18, 2015 01:59
-
-
Save adamyanalunas/5708195 to your computer and use it in GitHub Desktop.
Making real JSON from Mixpanel's dump API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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