How to set the text format of a field in a node object?
The following worked for me,

$node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;load($nid);
$node-&gt;body-&gt;value = 'body';
$node-&gt;body-&gt;format = 'full_html';//omitting this will retain existing format
$node-&gt;save();