Home > Software engineering >  Express.Js How to make a string parameter to a Json stringify Object?
Express.Js How to make a string parameter to a Json stringify Object?

Time:08-06

I have problem take the query (tree) from the api url and make it in the apropriate form for the function jsonTreeToTree.

This is what i should do:

You should implement the API: GET /api/tree/path-search. The aforementioned API call expects two parameters:

tree: A stringified JSON object representing a tree structure. It is defined as follows:

The tree node ids are depicted as the keys of the object If a tree node has kids then its value should be an object The keys of the objects under a tree node are the ids of its children tree nodes If a tree node does not have any kids then its value should be null

For example the object

{ 1 : { 2 : { 4 : null, 5 :null}, 3 : null}}

CodePudding user response:

why don't you save the object as is in your database and pull it using the primary key attached to the object? That should make for a cleaner API path

CodePudding user response:

There are a library which perfect fits what are you've looking for

qs library

It can handle objects to querystring and querystring to objects

  • Related