Manipulate a render array in hook_node_view I'm wanting to modify the contents of some fields at display time so looked at hook_node_view(), however, the $build array is not what I'm expecting, if I dump it with var_dump it is thousands of lines long and not in the format I'm expecting a render array to be, it includes all sorts of exciting things like SQL connection objects which are of no use to me but there is no obvious set of elements that I'd be expecting to see given the Drupal documentation. If I drill down the array, I can find the data I need, however, I can't see how to get this sorted in the correct display order. 

If I add a simple tweak like 

$build['title'] = ['#markup' =&gt; "Hello World"];


the node title is rendered correctly as the new value so I know I'm roughly in the right place.

Question, how can I get at the fields collection after extraction from the database and sorting into display order but before it hits the template as I need to be able to make changes at this point as future development will require potential output via differing templates.
Suggestions


Get the node from the $build (it should be in there somewhere) and build custom content for your field like $build['custom_field'] = [...].
Override the twig template for the field - this will let you alter the presentation of a particular field. Ex: implement node--field-custom-field.html.twig based on field.html.twig and alter the output of the field there.
Override the twig template for the entire node. Ex: implement node--article.html.twig based on node.html.twig and alter the output of the node there.


Let me know if any of these helps. More details on exactly what or why you want to alter stuff will be helpful.