How to transfer an array from php to json in ajax?

Broke to itself a head already, I'm a novice at this.
How to transfer an array from php to json in ajax?
Here's a piece of php code
$data['options'] = array();
 foreach ($this->model_catalog_product->getProductOptions($_POST['calc_id']) as $option) {
 $product_option_value_data = array();

 foreach ($option['product_option_value'] as $option_value) {
 if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {

 if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
 $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false));
 } else {
 $price = false;
}
 $json['calc_ids']['product_option_value_data']['product_option_value_id'][] = $option_value['product_option_value_id'];
 $json['calc_ids']['product_option_value_data']['option_value_id'][] = $option_value['option_value_id'];
 $json['calc_ids']['product_option_value_data']['name'][] = $option_value['name'];
 $json['calc_ids']['product_option_value_data']['price'][] = $price;
 $json['calc_ids']['product_option_value_data']['price_prefix'][] = $option_value['price_prefix'];
}
}
 $json['calc_ids']['options']['product_option_id'][] = $option['product_option_id'];
 $json['calc_ids']['options']['product_option_value'][] = $product_option_value_data;
 $json['calc_ids']['options']['option_id'][] = $option['option_id'];
 ******* $json['calc_ids']['options']['name'][] = $option['name']; *******
 $json['calc_ids']['options']['type'][] = $option['type'];
 $json['calc_ids']['options']['value'][] = $option['value'];
 $json['calc_ids']['options']['required'][] = $option['required'];
}
}

 $this->response->setOutput(json_encode($json));


here ajax

$(document).ready(function () {

 $('#calc_id').change(function () {

 var calc_id = $(this).val();

 $('#option_id').attr('disabled', true);
$('#option_id').html('<option>loading...</option>');

$.ajax({
 url: 'index.php?route=module/featured/write',
 type: 'post',
 dataType: 'json',
 data: 'calc_id='+calc_id, 
 success: function (data) {

 var obj = eval(data);


 var options = ";

 $(obj.calc_ids.options.name).each(function() {
 ******* alert(obj.calc_ids.options.name); *********
 options += '<option value>' + obj.calc_ids.options.name + '</option>';
});
$('#option_id').html(options);
 $('#option_id').attr('disabled', false); 
}
});

});
});


Stars said that trying to withdraw. Just why displays all the variables are comma-separated, but appear as many times as the array of variables (as it should be), just why all at once, separated by commas.
July 4th 19 at 23:36
2 answers
July 4th 19 at 23:38
Solution
Figured out finally
var obj = eval(data);

 var options = ";

 $(obj.calc_ids.options.name).each(function(index) {
alert(data['calc_ids']['options']['name'][index]);
 options += '<option value>' + data['calc_ids']['options']['name'][index] + '</option>';
 });


Inside the loop I didn't tell him to withdraw, and he led me the entire cycle, separated by commas. Added the index value and it worked. Thank you all for the answers.
July 4th 19 at 23:40
Need to be object and not an array. Ie the first character of the json should be { not [. Put all the data in some array, for example response, and then codicia in json. Also the head had a long break.
what is the first symbol you mean? - nikita.Stracke commented on July 4th 19 at 23:43
: email me what you have in the data - Kelsi43 commented on July 4th 19 at 23:46

Find more questions by tags AJAXJavaScriptJSONPHP