Last active
June 5, 2019 00:04
-
-
Save gpeal/9141bffb932fd77fbd1a469eec333b63 to your computer and use it in GitHub Desktop.
This will convet a Lottie json file that doesn't have "ty" properties at the beginning of the object to one that does.
This file contains 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
const fs = require('fs'); | |
convert = (json) => { | |
if (typeof json != "object") { | |
return json | |
} | |
for (var key in json) { | |
if (json.hasOwnProperty(key)) { | |
json[key] = convert(json[key]) | |
} | |
} | |
if (!!json["ty"]) { | |
const ty = json["ty"] | |
delete json["ty"] | |
return { "ty": ty, ...json } | |
} else { | |
return json | |
} | |
} | |
const file = JSON.parse(fs.readFileSync(process.argv[2])) | |
const converted = convert(file) | |
fs.writeFileSync(process.argv[2].replace(".json", "_conv.json"), JSON.stringify(converted)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment