Echo Menu located in primary navigation

You can use wp_get_nav_menu_items https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/ function to get your menu items in the form of an array , you can pass any of Menu ID, slug, name, or object in wp_get_nav_menu_items function.

$locations = get_nav_menu_locations();
$main_menu = wp_get_nav_menu_items($locations['primary']);
print_r($main_menu);

error code: 523