balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.83k stars 1.95k forks source link

Sails JS : Service to do json2json Conversion #2752

Closed rasekar2000 closed 9 years ago

rasekar2000 commented 9 years ago

Sub : JSON to JSON Conversion as part of service in Sails.js . Details : Let us consider the simple use case that 1 User can have Many (M) Pets. Basically 1 to M entity relationship. By calling the REST API - http://localhost:1337/user/1 , we will be able to get the User and the Pet information in REST JSON format. But my Client Side --> Angular JS or jQuery requires the JSON in another format .. For e.g. to display in a Tree Structure https://github.com/aexmachina/jquery-json-list/blob/master/example.json, looking forward the best practice. Thinking of this as a Solution : I wanted to have a server side json 2 json convertor. To achieve this for e.g have additional custom methods in User Controller that can call the Sails Service ( NodeJS service) to do the JSON2JSON conversion. Considering this json-formatter to perform this conversion.. https://github.com/evenemento/json-reformatter/blob/master/test/simple.test.js Can I please know, how this Sails JS Community achieve a better server side solution? Thanks in advance.

rasekar2000 commented 9 years ago

https://github.com/dregenor/jsonMapper is also looks clean.. Evaluating this as well for Json2Json conversion / mapping

rasekar2000 commented 9 years ago

Hi @tjwebb , Thanks very much for the invitation. I was evaluating these 5, which are already in the similar objective.

i) json2json https://github.com/joelvh/json2json is written in CoffeeScript and designed to run in a Node.js environment. It can be easily converted to JavaScript to be used in a browser as well.

ii) json-reformatter https://github.com/evenemento/json-reformatter/blob/master/test/simple.test.js → Looks promising in javascript based conversion

iii) jsonMapper https://github.com/dregenor/jsonMapper --> Much better

ii) NPM Json https://www.npmjs.com/package/json-map Utility to map one JavaScript object to another

iii) JOI Format (https://github.com/hapijs/joi) @ WalmartLabs

Should we improvise some of them unless you have compelling performance improvement. .. Congratulations for your contribution in Github in many projects and for your blog..

Regards, Raj

randallmeeker commented 9 years ago

Curious... How are these libraries different from lodash ?

rasekar2000 commented 9 years ago

Hi @randallmeeker ,

Thanks very much for the pointer. I reviewed lodash documentation. It provides detailed library.. http://stackoverflow.com/questions/25562706/use-lodash-to-transform-this-nested-json-data gave the confidence as well. Will evaluate and come back if required.

Thanks and Regards, Raj

rasekar2000 commented 9 years ago

Hi Travis Webb,

Technically we can close this ticket. I moved forward with LoDash. But this provides an opportunity for an enhancement requirement for SailsJS. I mean the REST API into some other Client Specific JSON formats. We do have JSON Schema(http://json-schema.org/ or http://jsonschema.net) , similar to XML Schema.

But again, I don't think, this will be highest priority, but you may consider low priority future enhancement. According to your thought, you can close this and have a separate Json2Json conversion feature issue for later action.

Thanks and Regards, Raj