–>This Format will work (Or) Not.
SELECT array_to_json(array_agg(outer)) FROM ( SELECT eCPRefAuth_Action_Code_Lookup_Category2 ( SELECT array_to_json(array_agg(Result)) FROM ( SELECT eCPRefAuth_Action_Code_Lookup_Category ,json_agg( row_to_json( ( SELECT t FROM ( SELECT eCPRefAuth_Action_Code_Lookup_Code, eCPRefAuth_Action_Code_Lookup_Desc ORDER BY eCPRefAuth_Action_Code_Lookup_Seq_level2 ) AS t(eCPRefAuth_Action_Code_Lookup_Code, eCPRefAuth_Action_Code_Lookup_Desc) ) ) ) AS available_codes FROM tbl_eCPRefAuth_Action_Code_Lookup GROUP BY eCPRefAuth_Action_Code_Lookup_Category, eCPRefAuth_Action_Code_Lookup_Seq_level1 ORDER BY eCPRefAuth_Action_Code_Lookup_Seq_level1 ) AS Result ) FROM tbl_eCPRefAuth_Action_Code_Lookup )as outer