I know that’s, but the point is how if I have a tree structure in DB and want to retrieve it to json.
this the query that i used in sql
SELECT t1.title AS lev1, t2.title as lev2, t3.title as lev3, t4.title as lev4
FROM category AS t1
LEFT JOIN category AS t2 ON t2.parent_id = t1.id_category
LEFT JOIN category AS t3 ON t3.parent_id = t2.id_category
LEFT JOIN category AS t4 ON t4.parent_id = t3.id_category
WHERE t1.title = 'ELECTRONIC';
the result
and I want to retrieve it to json like I mention in my post
Then read the data into equivalent structs or map[string]interface{} and use the already mentioned encoding/json package to get the JSON representation.
If there are any problems, show what you have so far and explain where you got stuck.