Encoding a Datamapper object to a json object requires a function from an extension. You can find ways to import extensions here: http://datamapper.wanwizard.eu/pages/extensions.html This is one way of doing it:
class Test extends DataMapper {
// Include the json extension
var $extensions = array('json');
.......
$test= new Test();
$test->where('id', $this->input->post('id'));
$test->select('id,name');
$test->get();
$test->set_json_content_type();
echo $test->all_to_json();
The fact that the 'city' column is there is normal. From the DataMapper user guide:
The object is populated with all objects from its corresponding table, but with only the title and description fields populated
To decode your JSON, you need to use this method (don't forget to import the extension if you haven't already)
$n = new Test();
$n->from_json([put your JSON string here]);