Where to put a script to provide AJAX/JSON response? I'm using drupal 7. I want to create a php script that uses Drupals DB abstraction layer to query the database and spit out JSON data.  Where would I place such a script?  At the moment, I've done it in a round-about way by create a new node, then in the function theme_process_page() of my theme/template.php, I wrote an IF statement to detect the node id, then run my code, then call a die() statement.

Is there a more appropriate place for me to put this script?

** additional notes **
This script is to be called every time a person presses "Provide a menu link" when adding/editing a node in the CMS.  The script will then automatically select the appropriate Parent Item and weight based on any other existing translation.
The easiest is to use Views datasources if it can solve your problem, in essence this means that if you can use views to display the data you need, you can use this module to return it as JSON.

Another option is to write a custom module and use hook_menu to define a 'menu' item which you can use from the calling code. To return your data as JSON you can use the standard php functions.

If you need multiple scripts and advanced configuration you can always have a look at Services or