Get Json From Module I have to create a module that return a list of my language, only the list without template,and I have to call this url via curl

I create something like this ( inside my module )

function my_module_menu() {
  $items['my_module'] = array( //URL
    'page callback' =&gt; 'get_all_languages',
    'access arguments' =&gt; array(''),
  );
  return $items;
}

/**
 * @return string
 */
function get_all_languages() {
    $out = array();
    $result = language_list('enabled');
    foreach ($result as $key =&gt; $value) {
      foreach ($value as $k =&gt; $v) {
        $out[$v-&gt;language] = $v-&gt;name;
      }
    }

    $p = json_encode($out);
    print $p;
    drupal_exit();
}


I tried also

  drupal_add_http_header('Content-Type', 'application/json');
  $p = drupal_json_encode($out);


But this url is not Json infact if call this url by Curl, I can see all the template.
I want to have the result like using this module, or can i Create a view that use my module result?

I have another problem when use curl, my content is


  You are not authorized to access this page.
Pretty close; here's the correct way:

/**
 * Implements hook_menu().
 */
function YOURMODULE_menu() {
  $items['languages'] = array(
    'page callback' =&gt; 'YOURMODULE_languages_enabled_json',
    'access callback' =&gt; TRUE,
  );
  return $items;
}

/**
 * Render enabled languages in JSON.
 */
function YOURMODULE_languages_enabled_json() {
  $out = array();
  foreach (language_list('enabled') as $languages) {
    foreach ($languages as $language) {
      $out[$language-&gt;language] = $language-&gt;name;
    }
  }
  drupal_json_output($out);
}


The important piece is https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_json_output/7 which should be used for JavaScript callback functions returning data in JSON format, and it sets the header for the JavaScript output.