const parse = data => {
const uid = `uid_${Date.now()}`;
const process = (input, prefix = '', json = {}) => {
Object.keys(input).forEach(key => {
const val = input[key];
if (!json.hasOwnProperty(`${prefix}${key}.`)) {
json[`${prefix}${key}.`] = uid;
}
if ('object' === typeof val && !Array.isArray(val) && !!val) {
process(val, `${prefix}${key}.`, json);
}
else {
json[`${prefix}${key}.`] = val;
}
});
return json;
};
const json = process(data);
const result = {};
Object.keys(json).forEach(key => {
if (json[key] !== uid) {
result[key.slice(0, -1)] = json[key];
}
});
return result;
};