const fs = require('fs') const treeUri = './json/tree.json' const modelUri = './json/request.json' const inputUri = './json/input.json' const _done = () => { const model = _getModelObj() const tree = _getConfigTree() const DATA = _converObj(model['DATA'], tree['DATA']) const input = { DATA } fs.writeFileSync(inputUri, JSON.stringify(input)) } const _getConfigTree = () => { return JSON.parse(fs.readFileSync(treeUri)) } const _getModelObj = () => { return JSON.parse(fs.readFileSync(modelUri)) } const _converObj = (model, tree) => { const tmp = {} for(const key in tree) { if(key === '_config' || key === '_key') { continue } const config = tree[key] const _config = config['_config'] const type = _config['type'] const mKey = _config['mKey'] if(type === 'object') { tmp[mKey] = _converObj(model[key], tree[key]) } else if(type === 'Array') { tmp[mKey] = _converArray(model[key], tree[key]) } else { tmp[mKey] = model[key] } } return tmp } const _converArray = (models, tree) => { const tmps = [] for(const model of models) { tmps.push(_converObj(model, tree)) } return tmps; } _done()