int oph_json_add_multigrid(oph_json *json, const char *objkey, const char *title, const char *description, const char **rowkeys, int rowkeys_num, const char **rowfieldtypes, int rowfieldtypes_num, const char **colkeys, int colkeys_num, const char **colfieldtypes, int colfieldtypes_num, const char ***colvalues, int colvalues_num, const char *measurename, const char *measuretype) {
	if (!json || !objkey || !title || !rowkeys || rowkeys_num<1 || !rowfieldtypes || rowfieldtypes_num<1 || !colkeys || colkeys_num<1 || !colfieldtypes || colfieldtypes_num<1 || !colvalues || colvalues_num<1 || !measurename || !measuretype) {
		return OPH_JSON_BAD_PARAM_ERROR;
	}

	if (json->response_num == 0) {
		json->response = (oph_json_response *)malloc(sizeof(oph_json_response));
		if (!json->response) {
			return OPH_JSON_MEMORY_ERROR;
		}
		json->response[0].objclass = NULL;
		json->response[0].objcontent = NULL;
		json->response[0].objcontent_num = 0;
		json->response[0].objkey = NULL;

		json->response[0].objclass = (char *)strdup(OPH_JSON_MULTIGRID);
		if (!json->response[0].objclass) {
			return OPH_JSON_MEMORY_ERROR;
		}

		json->response_num++;

		json->response[0].objkey = (char *)strdup(objkey);
		if (!json->response[0].objkey) {
			return OPH_JSON_MEMORY_ERROR;
		}
		if (oph_json_add_responseKey(json,objkey)) {
			return OPH_JSON_MEMORY_ERROR;
		}

		json->response[0].objcontent = malloc(sizeof(oph_json_obj_multigrid));
		if (!json->response[0].objcontent) {
			return OPH_JSON_MEMORY_ERROR;
		}
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes_num = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys_num = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues_num1 = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues_num2 = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].description = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurename = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measuretype = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurevalues = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurevalues_num1 = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurevalues_num2 = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes_num = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys_num = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowvalues = NULL;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowvalues_num1 = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowvalues_num2 = 0;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].title = NULL;

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].title = (char *)strdup(title);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].title) {
			return OPH_JSON_MEMORY_ERROR;
		}

		json->response[0].objcontent_num++;

		if (description) {
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].description = (char *)strdup(description);
			if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].description) {
				return OPH_JSON_MEMORY_ERROR;
			}
		}

		size_t k,q;

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys = (char **)malloc(sizeof(char *)*rowkeys_num);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys) {
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < (size_t)rowkeys_num; k++) {
			for (q = 0; q < k; q++) {
				if (!strcmp(rowkeys[q],rowkeys[k])) {
					return OPH_JSON_BAD_PARAM_ERROR;
				}
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys[k] = (char *)strdup(rowkeys[k]);
			if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys[k]) {
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowkeys_num++;
		}

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes = (char **)malloc(sizeof(char *)*rowfieldtypes_num);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes) {
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < (size_t)rowfieldtypes_num; k++) {
			if (!oph_json_is_type_correct(rowfieldtypes[k])) {
				return OPH_JSON_BAD_PARAM_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes[k] = (char *)strdup(rowfieldtypes[k]);
			if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes[k]) {
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowfieldtypes_num++;
		}

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys = (char **)malloc(sizeof(char *)*colkeys_num);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys) {
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < (size_t)colkeys_num; k++) {
			for (q = 0; q < k; q++) {
				if (!strcmp(colkeys[q],colkeys[k])) {
					return OPH_JSON_BAD_PARAM_ERROR;
				}
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys[k] = (char *)strdup(colkeys[k]);
			if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys[k]) {
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colkeys_num++;
		}

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes = (char **)malloc(sizeof(char *)*colfieldtypes_num);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes) {
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < (size_t)colfieldtypes_num; k++) {
			if (!oph_json_is_type_correct(colfieldtypes[k])) {
				return OPH_JSON_BAD_PARAM_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes[k] = (char *)strdup(colfieldtypes[k]);
			if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes[k]) {
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colfieldtypes_num++;
		}

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues = (char ***)malloc(sizeof(char **)*colvalues_num);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues) {
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < (size_t)colvalues_num; k++) {
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues[k] = NULL;
		}
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues_num1 = colvalues_num;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues_num2 = colkeys_num;
		for (k = 0; k < (size_t)colvalues_num; k++) {
			((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues[k] = (char **)malloc(sizeof(char *)*colkeys_num);
			if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues[k]) {
				return OPH_JSON_MEMORY_ERROR;
			}

			for (q = 0; q < (size_t)colkeys_num; q++) {
				((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues[k][q] = NULL;
			}
			for (q = 0; q < (size_t)colkeys_num; q++) {
				((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues[k][q] = (char *)strdup(colvalues[k][q]);
				if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].colvalues[k][q]) {
					return OPH_JSON_MEMORY_ERROR;
				}
			}
		}

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurename = (char *)strdup(measurename);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurename) {
			return OPH_JSON_MEMORY_ERROR;
		}

		if (!oph_json_is_measuretype_correct(measuretype)) {
			return OPH_JSON_BAD_PARAM_ERROR;
		}
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measuretype = (char *)strdup(measuretype);
		if (!((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measuretype) {
			return OPH_JSON_MEMORY_ERROR;
		}

		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].measurevalues_num2 = colvalues_num;
		((oph_json_obj_multigrid *) json->response[0].objcontent)[0].rowvalues_num2 = rowkeys_num;

	} else {
		size_t i;
		int add_frag = 0;
		for (i = 0; i < json->response_num; i++) {
			if (!strcmp(json->response[i].objkey,objkey)) {
				if (!strcmp(json->response[i].objclass,OPH_JSON_MULTIGRID)) {
					add_frag = 1;
					break;
				}
				return OPH_JSON_BAD_PARAM_ERROR;
			}
		}
		if (add_frag) {
			void *tmp = json->response[i].objcontent;
			unsigned int index = json->response[i].objcontent_num;
			json->response[i].objcontent = realloc(json->response[i].objcontent,sizeof(oph_json_obj_multigrid)*(json->response[i].objcontent_num + 1));
			if (!json->response[i].objcontent) {
				json->response[i].objcontent = tmp;
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes_num = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys_num = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues_num1 = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues_num2 = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].description = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurename = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measuretype = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurevalues = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurevalues_num1 = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurevalues_num2 = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes_num = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys_num = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowvalues = NULL;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowvalues_num1 = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowvalues_num2 = 0;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].title = NULL;

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].title = (char *)strdup(title);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].title) {
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response[i].objcontent_num++;

			if (description) {
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].description = (char *)strdup(description);
				if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].description) {
					return OPH_JSON_MEMORY_ERROR;
				}
			}

			size_t k,q;

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys = (char **)malloc(sizeof(char *)*rowkeys_num);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)rowkeys_num; k++) {
				for (q = 0; q < k; q++) {
					if (!strcmp(rowkeys[q],rowkeys[k])) {
						return OPH_JSON_BAD_PARAM_ERROR;
					}
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys[k] = (char *)strdup(rowkeys[k]);
				if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowkeys_num++;
			}

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes = (char **)malloc(sizeof(char *)*rowfieldtypes_num);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)rowfieldtypes_num; k++) {
				if (!oph_json_is_type_correct(rowfieldtypes[k])) {
					return OPH_JSON_BAD_PARAM_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes[k] = (char *)strdup(rowfieldtypes[k]);
				if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowfieldtypes_num++;
			}

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys = (char **)malloc(sizeof(char *)*colkeys_num);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)colkeys_num; k++) {
				for (q = 0; q < k; q++) {
					if (!strcmp(colkeys[q],colkeys[k])) {
						return OPH_JSON_BAD_PARAM_ERROR;
					}
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys[k] = (char *)strdup(colkeys[k]);
				if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colkeys_num++;
			}

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes = (char **)malloc(sizeof(char *)*colfieldtypes_num);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)colfieldtypes_num; k++) {
				if (!oph_json_is_type_correct(colfieldtypes[k])) {
					return OPH_JSON_BAD_PARAM_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes[k] = (char *)strdup(colfieldtypes[k]);
				if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colfieldtypes_num++;
			}

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues = (char ***)malloc(sizeof(char **)*colvalues_num);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)colvalues_num; k++) {
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues[k] = NULL;
			}
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues_num1 = colvalues_num;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues_num2 = colkeys_num;
			for (k = 0; k < (size_t)colvalues_num; k++) {
				((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues[k] = (char **)malloc(sizeof(char *)*colkeys_num);
				if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}

				for (q = 0; q < (size_t)colkeys_num; q++) {
					((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues[k][q] = NULL;
				}
				for (q = 0; q < (size_t)colkeys_num; q++) {
					((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues[k][q] = (char *)strdup(colvalues[k][q]);
					if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].colvalues[k][q]) {
						return OPH_JSON_MEMORY_ERROR;
					}
				}
			}

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurename = (char *)strdup(measurename);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurename) {
				return OPH_JSON_MEMORY_ERROR;
			}

			if (!oph_json_is_measuretype_correct(measuretype)) {
				return OPH_JSON_BAD_PARAM_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measuretype = (char *)strdup(measuretype);
			if (!((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measuretype) {
				return OPH_JSON_MEMORY_ERROR;
			}

			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].measurevalues_num2 = colvalues_num;
			((oph_json_obj_multigrid *) json->response[i].objcontent)[index].rowvalues_num2 = rowkeys_num;

		} else {
			oph_json_response *tmp = json->response;
			unsigned int index = json->response_num;
			json->response = (oph_json_response *)realloc(json->response,sizeof(oph_json_response)*(json->response_num + 1));
			if (!json->response) {
				json->response = tmp;
				return OPH_JSON_MEMORY_ERROR;
			}
			json->response[index].objclass = NULL;
			json->response[index].objcontent = NULL;
			json->response[index].objcontent_num = 0;
			json->response[index].objkey = NULL;

			json->response[index].objclass = (char *)strdup(OPH_JSON_MULTIGRID);
			if (!json->response[index].objclass) {
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response_num++;

			json->response[index].objkey = (char *)strdup(objkey);
			if (!json->response[index].objkey) {
				return OPH_JSON_MEMORY_ERROR;
			}
			if (oph_json_add_responseKey(json,objkey)) {
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response[index].objcontent = malloc(sizeof(oph_json_obj_multigrid));
			if (!json->response[index].objcontent) {
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes_num = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys_num = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues_num1 = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues_num2 = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].description = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurename = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measuretype = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurevalues = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurevalues_num1 = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurevalues_num2 = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes_num = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys_num = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowvalues = NULL;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowvalues_num1 = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowvalues_num2 = 0;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].title = NULL;

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].title = (char *)strdup(title);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].title) {
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response[index].objcontent_num++;

			if (description) {
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].description = (char *)strdup(description);
				if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].description) {
					return OPH_JSON_MEMORY_ERROR;
				}
			}

			size_t k,q;

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys = (char **)malloc(sizeof(char *)*rowkeys_num);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)rowkeys_num; k++) {
				for (q = 0; q < k; q++) {
					if (!strcmp(rowkeys[q],rowkeys[k])) {
						return OPH_JSON_BAD_PARAM_ERROR;
					}
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys[k] = (char *)strdup(rowkeys[k]);
				if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowkeys_num++;
			}

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes = (char **)malloc(sizeof(char *)*rowfieldtypes_num);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)rowfieldtypes_num; k++) {
				if (!oph_json_is_type_correct(rowfieldtypes[k])) {
					return OPH_JSON_BAD_PARAM_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes[k] = (char *)strdup(rowfieldtypes[k]);
				if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowfieldtypes_num++;
			}

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys = (char **)malloc(sizeof(char *)*colkeys_num);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)colkeys_num; k++) {
				for (q = 0; q < k; q++) {
					if (!strcmp(colkeys[q],colkeys[k])) {
						return OPH_JSON_BAD_PARAM_ERROR;
					}
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys[k] = (char *)strdup(colkeys[k]);
				if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colkeys_num++;
			}

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes = (char **)malloc(sizeof(char *)*colfieldtypes_num);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)colfieldtypes_num; k++) {
				if (!oph_json_is_type_correct(colfieldtypes[k])) {
					return OPH_JSON_BAD_PARAM_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes[k] = (char *)strdup(colfieldtypes[k]);
				if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colfieldtypes_num++;
			}

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues = (char ***)malloc(sizeof(char **)*colvalues_num);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues) {
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < (size_t)colvalues_num; k++) {
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues[k] = NULL;
			}
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues_num1 = colvalues_num;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues_num2 = colkeys_num;
			for (k = 0; k < (size_t)colvalues_num; k++) {
				((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues[k] = (char **)malloc(sizeof(char *)*colkeys_num);
				if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues[k]) {
					return OPH_JSON_MEMORY_ERROR;
				}

				for (q = 0; q < (size_t)colkeys_num; q++) {
					((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues[k][q] = NULL;
				}
				for (q = 0; q < (size_t)colkeys_num; q++) {
					((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues[k][q] = (char *)strdup(colvalues[k][q]);
					if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].colvalues[k][q]) {
						return OPH_JSON_MEMORY_ERROR;
					}
				}
			}

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurename = (char *)strdup(measurename);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurename) {
				return OPH_JSON_MEMORY_ERROR;
			}

			if (!oph_json_is_measuretype_correct(measuretype)) {
				return OPH_JSON_BAD_PARAM_ERROR;
			}
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measuretype = (char *)strdup(measuretype);
			if (!((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measuretype) {
				return OPH_JSON_MEMORY_ERROR;
			}

			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].measurevalues_num2 = colvalues_num;
			((oph_json_obj_multigrid *) json->response[index].objcontent)[0].rowvalues_num2 = rowkeys_num;

		}
	}

	return OPH_JSON_SUCCESS;
}
int oph_json_add_grid(oph_json *json, const char *objkey, const char *title, const char *description, char **keys, int keys_num, char **fieldtypes, int fieldtypes_num) {
	if (!json || !objkey || !title || !keys || keys_num<1 || !fieldtypes || fieldtypes_num<1) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "(NULL parameters)");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "(NULL parameters)");
		return OPH_JSON_BAD_PARAM_ERROR;
	}

	if (json->response_num == 0) {
		json->response = (oph_json_response *)malloc(sizeof(oph_json_response));
		if (!json->response) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "response");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "response");
			return OPH_JSON_MEMORY_ERROR;
		}
		json->response[0].objclass = NULL;
		json->response[0].objcontent = NULL;
		json->response[0].objcontent_num = 0;
		json->response[0].objkey = NULL;

		json->response[0].objclass = (char *)strdup(OPH_JSON_GRID);
		if (!json->response[0].objclass) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objclass");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objclass");
			return OPH_JSON_MEMORY_ERROR;
		}

		json->response_num++;

		json->response[0].objkey = (char *)strdup(objkey);
		if (!json->response[0].objkey) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
			return OPH_JSON_MEMORY_ERROR;
		}
		if (oph_json_add_responseKey(json,objkey)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
			return OPH_JSON_MEMORY_ERROR;
		}

		json->response[0].objcontent = malloc(sizeof(oph_json_obj_grid));
		if (!json->response[0].objcontent) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objcontent");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objcontent");
			return OPH_JSON_MEMORY_ERROR;
		}
		((oph_json_obj_grid *) json->response[0].objcontent)[0].description = NULL;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes = NULL;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes_num = 0;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].keys = NULL;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].keys_num = 0;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].title = NULL;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].values = NULL;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].values_num1 = 0;
		((oph_json_obj_grid *) json->response[0].objcontent)[0].values_num2 = 0;

		((oph_json_obj_grid *) json->response[0].objcontent)[0].title = (char *)strdup(title);
		if (!((oph_json_obj_grid *) json->response[0].objcontent)[0].title) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "title");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "title");
			return OPH_JSON_MEMORY_ERROR;
		}

		json->response[0].objcontent_num++;

		if (description) {
			((oph_json_obj_grid *) json->response[0].objcontent)[0].description = (char *)strdup(description);
			if (!((oph_json_obj_grid *) json->response[0].objcontent)[0].description) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "description");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "description");
				return OPH_JSON_MEMORY_ERROR;
			}
		}

		int k,q;

		((oph_json_obj_grid *) json->response[0].objcontent)[0].keys = (char **)malloc(sizeof(char *)*keys_num);
		if (!((oph_json_obj_grid *) json->response[0].objcontent)[0].keys) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "keys");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "keys");
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < keys_num; k++) {
			for (q = 0; q < k; q++) {
				if (!strcmp(keys[q],keys[k])) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "key");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "key");
					return OPH_JSON_BAD_PARAM_ERROR;
				}
			}
			((oph_json_obj_grid *) json->response[0].objcontent)[0].keys[k] = (char *)strdup(keys[k]);
			if (!((oph_json_obj_grid *) json->response[0].objcontent)[0].keys[k]) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "key");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "key");
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_grid *) json->response[0].objcontent)[0].keys_num++;
		}

		((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes = (char **)malloc(sizeof(char *)*fieldtypes_num);
		if (!((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "fieldtypes");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "fieldtypes");
			return OPH_JSON_MEMORY_ERROR;
		}
		for (k = 0; k < fieldtypes_num; k++) {
			if (!oph_json_is_type_correct(fieldtypes[k])) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "fieldtype");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "fieldtype");
				return OPH_JSON_BAD_PARAM_ERROR;
			}
			((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes[k] = (char *)strdup(fieldtypes[k]);
			if (!((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes[k]) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "fieldtype");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "fieldtype");
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes_num++;
		}

		if (keys_num != fieldtypes_num || (unsigned int)keys_num != ((oph_json_obj_grid *) json->response[0].objcontent)[0].keys_num || (unsigned int)fieldtypes_num != ((oph_json_obj_grid *) json->response[0].objcontent)[0].fieldtypes_num) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "keys_num/fieldtypes_num");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "keys_num/fieldtypes_num");
			return OPH_JSON_BAD_PARAM_ERROR;
		}

		((oph_json_obj_grid *) json->response[0].objcontent)[0].values_num2 = ((oph_json_obj_grid *) json->response[0].objcontent)[0].keys_num;
	} else {
		unsigned int i;
		int add_frag = 0;
		for (i = 0; i < json->response_num; i++) {
			if (!strcmp(json->response[i].objkey,objkey)) {
				if (!strcmp(json->response[i].objclass,OPH_JSON_GRID)) {
					add_frag = 1;
					break;
				}
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "objkey");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "objkey");
				return OPH_JSON_BAD_PARAM_ERROR;
			}
		}
		if (add_frag) {
			void *tmp = json->response[i].objcontent;
			unsigned int index = json->response[i].objcontent_num;
			json->response[i].objcontent = realloc(json->response[i].objcontent,sizeof(oph_json_obj_grid)*(json->response[i].objcontent_num + 1));
			if (!json->response[i].objcontent) {
				json->response[i].objcontent = tmp;
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objcontent");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objcontent");
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_grid *) json->response[i].objcontent)[index].description = NULL;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes = NULL;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes_num = 0;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].keys = NULL;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].keys_num = 0;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].title = NULL;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].values = NULL;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].values_num1 = 0;
			((oph_json_obj_grid *) json->response[i].objcontent)[index].values_num2 = 0;

			((oph_json_obj_grid *) json->response[i].objcontent)[index].title = (char *)strdup(title);
			if (!((oph_json_obj_grid *) json->response[i].objcontent)[index].title) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "title");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "title");
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response[i].objcontent_num++;

			if (description) {
				((oph_json_obj_grid *) json->response[i].objcontent)[index].description = (char *)strdup(description);
				if (!((oph_json_obj_grid *) json->response[i].objcontent)[index].description) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "description");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "description");
					return OPH_JSON_MEMORY_ERROR;
				}
			}

			int k,q;

			((oph_json_obj_grid *) json->response[i].objcontent)[index].keys = (char **)malloc(sizeof(char *)*keys_num);
			if (!((oph_json_obj_grid *) json->response[i].objcontent)[index].keys) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "keys");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "keys");
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < keys_num; k++) {
				for (q = 0; q < k; q++) {
					if (!strcmp(keys[q],keys[k])) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "key");
						logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "key");
						return OPH_JSON_BAD_PARAM_ERROR;
					}
				}
				((oph_json_obj_grid *) json->response[i].objcontent)[index].keys[k] = (char *)strdup(keys[k]);
				if (!((oph_json_obj_grid *) json->response[i].objcontent)[index].keys[k]) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "key");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "key");
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_grid *) json->response[i].objcontent)[index].keys_num++;
			}

			((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes = (char **)malloc(sizeof(char *)*fieldtypes_num);
			if (!((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "fieldtypes");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "fieldtypes");
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < fieldtypes_num; k++) {
				if (!oph_json_is_type_correct(fieldtypes[k])) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "fieldtype");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "fieldtype");
					return OPH_JSON_BAD_PARAM_ERROR;
				}
				((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes[k] = (char *)strdup(fieldtypes[k]);
				if (!((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes[k]) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "fieldtype");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "fieldtype");
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes_num++;
			}

			if (keys_num != fieldtypes_num || (unsigned int)keys_num != ((oph_json_obj_grid *) json->response[i].objcontent)[index].keys_num || (unsigned int)fieldtypes_num != ((oph_json_obj_grid *) json->response[i].objcontent)[index].fieldtypes_num) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "keys_num/fieldtypes_num");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "keys_num/fieldtypes_num");
				return OPH_JSON_BAD_PARAM_ERROR;
			}

			((oph_json_obj_grid *) json->response[i].objcontent)[index].values_num2 = ((oph_json_obj_grid *) json->response[i].objcontent)[index].keys_num;
		} else {
			oph_json_response *tmp = json->response;
			unsigned int index = json->response_num;
			json->response = (oph_json_response *)realloc(json->response,sizeof(oph_json_response)*(json->response_num + 1));
			if (!json->response) {
				json->response = tmp;
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "response");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "response");
				return OPH_JSON_MEMORY_ERROR;
			}
			json->response[index].objclass = NULL;
			json->response[index].objcontent = NULL;
			json->response[index].objcontent_num = 0;
			json->response[index].objkey = NULL;

			json->response[index].objclass = (char *)strdup(OPH_JSON_GRID);
			if (!json->response[index].objclass) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objclass");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objclass");
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response_num++;

			json->response[index].objkey = (char *)strdup(objkey);
			if (!json->response[index].objkey) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
				return OPH_JSON_MEMORY_ERROR;
			}
			if (oph_json_add_responseKey(json,objkey)) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objkey");
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response[index].objcontent = malloc(sizeof(oph_json_obj_grid));
			if (!json->response[index].objcontent) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "objcontent");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "objcontent");
				return OPH_JSON_MEMORY_ERROR;
			}
			((oph_json_obj_grid *) json->response[index].objcontent)[0].description = NULL;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes = NULL;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes_num = 0;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].keys = NULL;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].keys_num = 0;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].title = NULL;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].values = NULL;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].values_num1 = 0;
			((oph_json_obj_grid *) json->response[index].objcontent)[0].values_num2 = 0;

			((oph_json_obj_grid *) json->response[index].objcontent)[0].title = (char *)strdup(title);
			if (!((oph_json_obj_grid *) json->response[index].objcontent)[0].title) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "title");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "title");
				return OPH_JSON_MEMORY_ERROR;
			}

			json->response[index].objcontent_num++;

			if (description) {
				((oph_json_obj_grid *) json->response[index].objcontent)[0].description = (char *)strdup(description);
				if (!((oph_json_obj_grid *) json->response[index].objcontent)[0].description) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "description");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "description");
					return OPH_JSON_MEMORY_ERROR;
				}
			}

			int k,q;

			((oph_json_obj_grid *) json->response[index].objcontent)[0].keys = (char **)malloc(sizeof(char *)*keys_num);
			if (!((oph_json_obj_grid *) json->response[index].objcontent)[0].keys) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "keys");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "keys");
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < keys_num; k++) {
				for (q = 0; q < k; q++) {
					if (!strcmp(keys[q],keys[k])) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "key");
						logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "key");
						return OPH_JSON_BAD_PARAM_ERROR;
					}
				}
				((oph_json_obj_grid *) json->response[index].objcontent)[0].keys[k] = (char *)strdup(keys[k]);
				if (!((oph_json_obj_grid *) json->response[index].objcontent)[0].keys[k]) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "key");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "key");
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_grid *) json->response[index].objcontent)[0].keys_num++;
			}

			((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes = (char **)malloc(sizeof(char *)*fieldtypes_num);
			if (!((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "fieldtypes");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "fieldtypes");
				return OPH_JSON_MEMORY_ERROR;
			}
			for (k = 0; k < fieldtypes_num; k++) {
				if (!oph_json_is_type_correct(fieldtypes[k])) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "fieldtype");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "fieldtype");
					return OPH_JSON_BAD_PARAM_ERROR;
				}
				((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes[k] = (char *)strdup(fieldtypes[k]);
				if (!((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes[k]) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_MEMORY_ERROR, "fieldtype");
					logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_MEMORY_ERROR, "fieldtype");
					return OPH_JSON_MEMORY_ERROR;
				}
				((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes_num++;
			}

			if (keys_num != fieldtypes_num || (unsigned int)keys_num != ((oph_json_obj_grid *) json->response[index].objcontent)[0].keys_num || (unsigned int)fieldtypes_num != ((oph_json_obj_grid *) json->response[index].objcontent)[0].fieldtypes_num) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_JSON_LOG_BAD_PARAM_ERROR, "keys_num/fieldtypes_num");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_JSON_LOG_BAD_PARAM_ERROR, "keys_num/fieldtypes_num");
				return OPH_JSON_BAD_PARAM_ERROR;
			}

			((oph_json_obj_grid *) json->response[index].objcontent)[0].values_num2 = ((oph_json_obj_grid *) json->response[index].objcontent)[0].keys_num;
		}
	}

	return OPH_JSON_SUCCESS;
}