I am very new in WordPress and I have to create an API to get a list of category and it's subcategory of top navigation in WordPress.
wp_get_nav_menu_items( string $menu )
$menu =
(string) (Required) Menu name, ID, or slug.
you can use this function to print out all the menu item with submenu