Skip to content

Instantly share code, notes, and snippets.

@gpeal
Last active June 5, 2019 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpeal/9141bffb932fd77fbd1a469eec333b63 to your computer and use it in GitHub Desktop.
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.
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