Hi Suresh, What is your idea to resolve this issue? You thinking of writing regex based util to fill in placeholders?
On Monday, December 25, 2017 at 11:30:22 AM UTC-5, kallem suresh wrote: > > Hi, > > I might resolve this issue and lets connect with me so I will take remote > control and resolve the issue. > > Thanks, > Suresh K > > On Saturday, December 23, 2017 at 3:59:03 PM UTC+5:30, Lucky Jindal wrote: >> >> Hi, >> I am fairly new to node stack and still learning. I am new to this forum >> and I hope someone could help me fixing my problem here. >> >> Right now, I am working on backend (express.js) where I need to deal to >> lot of JSON for writing restful apis. >> >> Application - Front end sends form data in JSON format ( data model. >> json) and it is sent to backend. Backend router accepts POST request with >> form data and does something with it, transforms it into some another JSON >> format, say, object.json and sends it over to external server via POST and >> gets 200 OK. Now, I am dealing with huge and nested JSONs and many calls >> over http to 3rd party server. >> >> My problem here: Since both JSONs, data model JSON and object. json are >> in completely different format, transforming is hard part. Since they are >> written by different teams, it kind of hard to have matching fields/keys. >> >> Example . >> *1. "data.json" *-> Coming from Angular front end, it has form data and >> sent when form submitted like- >> *{ name : "ASC", id : "101".....}* >> >> 2. In backend, I have router methods, which gets this POST call and >> >> ~ accept data.json (with data) >> ~ read another json, *"object.json"* which is more like a template. >> This is in the format accepted by restful api on external server. So we >> have to use this, fill in it with data from data.json and send it over. >> ~ *"object.json "* >> {username : "", userId : "".... } >> >> So Idea is, I read data from data.json and fill in template.json and send >> it over. >> >> I tried 2 methods --- >> 1. Traverse over keys in *object.json* one by one and fill in manually, >> which seems lot of work and these are huge jsons. This was working until I >> realized, its getting cumbersome. >> 2. Using some external templating API. One I tried was *json-templater.* >> >> >> Now, my template.json >> ~ {username : "{{uname}}", userId : "{{uid}}" } . Values in {{}} will be >> filled up by this new api. >> ~ >> var object = require (../json-templater) >> return object( require(object.json, {uname :"ABC"}} >> >> It worked partially. >> >> Results returned by 'return' are same as I want. But something is >> changed, format. Because results are rejected by external server. If I >> comment this call, and hardcode same results, it works ok. >> Since I am just learning and trying to make it work and trying to find >> out what happened, I hard coded all the data in "object.json" and still run >> object function in json-template and it breaks. >> Only way it works is, not passing it through object function in >> json-templater. >> >> >> Any ideas to make this work or new API or any other approach. Suggestions >> welcome. >> >> Thanks >> >> >> >> >> >> >> >>> >>> -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/4765ecaa-739d-4a11-9465-119b96b0eef7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.