Store field values in a JSON file? I'm building a booking calendar module, and want to get back arrival &amp; departure datefields values to highlight reservations on the calendar, passing to a library the variables.

public function showCalendarAction() {       
        return [            
            '#attached'=&gt; ['library'=&gt; ['my_booking_calendar/my_booking_calendar.popperjs']],
            '#attached'=&gt; ['library'=&gt; ['my_booking_calendar/my_booking_calendar.bootstrap']],
            '#attached'=&gt; ['library'=&gt; ['my_booking_calendar/my_booking_calendar.bootstrap_year_calendar']],
            '#markup'=&gt;$this-&gt;t('&lt;div data-provide="calendar"&gt;&lt;/div&gt;')
        ];
    }


I intended to store all the dates(linked to one hotel/house) in a json file, that I would call in ajax.

If it's a good Drupal 8 practice, how to do this ?

Else, what would be the good way to store and pass the variables to my module library ?
You could use the routing system and create a custom route and output your json within the controller. 

After that you can load the url in your ajax call.

module.routing.yml (path_to_module/):

  module.content:
  path: '/json-output'
  defaults:
    _controller: '\Drupal\module\Controller\ModuleController::content'

  requirements:
    _permission: 'access content'


ModuleController.php (path_to_module/src/Controller/):

&lt;?php

namespace Drupal\module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Response;

/**
 * An example controller.
 */
class ModuleController extends ControllerBase {

  /**
   * {@inheritdoc}
   */
  public function content() {
    // Load your json content here.
    $json = module_get_json();

    $response = new Response();
    $response-&gt;setContent($json);
    $response-&gt;headers-&gt;set('Content-Type', 'application/json');
    return $response;

  }

}


Now you can load your json via /json-output. It is also possible to pass variables to the controller via the url.