Skip to content

Instantly share code, notes, and snippets.

@KoKuToru
Created August 12, 2016 10:13
Show Gist options
  • Save KoKuToru/a9ff1da8f77516ecc802427ef858e1ef to your computer and use it in GitHub Desktop.
Save KoKuToru/a9ff1da8f77516ecc802427ef858e1ef to your computer and use it in GitHub Desktop.
function jsonToEmber(obj) {
if (obj instanceof Array) {
return Ember.A(obj.map(y => jsonToEmber(y)));
} else if (obj instanceof Object) {
let tmp = {};
for (const x of Object.keys(obj)) {
if (obj[x] instanceof Array) {
tmp[x] = Ember.A(obj[x].map(y => jsonToEmber(y)));
} else if (obj[x] instanceof Object) {
tmp[x] = jsonToEmber(obj[x]);
} else {
tmp[x] = obj[x];
}
}
return Ember.Object.create(tmp);
} else {
return obj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment