I am using JSON API module to expose data using REST API. I want to alter its response. I am trying to altering it using hook_ENTITY_TYPE_load
. If I change any existing property it shows the updated value. But if I try to add custom property it doesn't show the custom property in response. The two hooks I used are below:
function my_custom_entity_type_alter(array &$entity_types) {
$entity_types['node']->set('flag_count', 10);
}
function my_custom_node_load($nodes) {
foreach ($nodes as &$node) {
$node->flag_count = 10;
}
}
I need to know if there is any possible way to alter the json api response with custom properties?