How to get the field and value of a content type in drupal 8? I wanted to create a module that fetch the entire data from my custom content type to  generate a json file. So I used the function

$values = \Drupal\Core\Entity\ContentEntityBase::get('field_name');

to read the field and its values of a content type. Any way to dynamically fetch all the fields and its values. Any solution?
Thanks in advance..:D
You can get all the field definitions for a content type using getFieldDefinitions from the Entity Field Manager service. The definitions are indexed by field name, so you can iterate on the keys of the returned array for any of the nodes in your site.

An example would be the following:

&lt;?php
  // Get the definitions
  $definitions = \Drupal::service('entity_field.manager')-&gt;getFieldDefinitions('node', 'my_custom_content');

  // Load a node for which you want to get the field values
  $my_node = \Drupal\node\Entity\Node::load($my_nid);

  // Iterate through the definitions
  foreach (array_keys($definitions) as $field_name) {
    // Get the values for your node
    // Use getValue() if you want to get an array instead of text.
    $values[$field_name] = $my_node-&gt;get($field_name)-&gt;value;
  }