Changed write in search handler to use write_json