Drupal 6 json API

This is how you can create a API returning json in Drupal 6.

<?php
function adwords_url_check($type = FALSE){
   
$matches = array();
   
    if(
$result = db_query("SELECT n.nid, field_mcc_id_value, field_account_id_value, field_receiver_email_value, field_last_sent_email_value, field_interval_days_value FROM {node} AS n LEFT JOIN {content_type_adwords_url_check} USING(vid) WHERE n.status = 1 AND n.type = 'adwords_url_check'")) {
      while (
$data = db_fetch_array($result)) {
       
array_push($matches, $data);
      }
    }
   
    if (
$type == "serialized") {
        print
serialize($matches);
        exit;   
    }else{
        echo
json_encode($matches);
        exit;
    }

}
?>

You might need to set the header as well.

<?php
   
if($result = mysql_query("SELECT * FROM `chess` WHERE `uid` = ".$_POST['uid']." AND `moveCount` = ".$_POST['moveCount'].";", $link)) {
     
$data = mysql_fetch_array($result);
    }

    if (empty(
$data)) {
       
$data['FEN'] = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR';
    }
   
header('Content-Type: application/json');
    echo
json_encode($data);
    exit;
?>
Knowledge keywords: