0

While updating, couchDB json documents having two separate arrays. But i push one array into particular array of objects.

 {

"_id":"employee_skill_doc",
"_rev":"269-e99377ad5d9e746a9d5b4777e7a50e46",
 "skills":[
 {
  "skill_name": "Dassault Simulia",
  "skill_id": "En17",
  "skill_set_id": "c03",
  "skill_set": "CAE (Computer Aided Engineering)",
  "skill_sub_ID": "b02",
  "skill_cat_ID": "a01"
 }],
 "certification":[
 {
  "certification_type": "networking",
  "certification_company": "citrix",
  "certification_name": "citrix",
  "certified_year": "1992",
  "certified_valitidy": "01/2014",
  "marks":"90",
  "comments":"sample",
  "skill_id": "En17"
 }]
 }

Here, mentioned the expected output,

{

"_id": "employee_skill_doc",
"_rev": "269-e99377ad5d9e746a9d5b4777e7a50e46",
"skills": [{
 "skill_name": "Dassault Simulia",
 "skill_id": "En17","skill_set_id": "c03",
 "skill_set": "CAE (Computer Aided Engineering)",
 "skill_sub_ID": "b02","skill_cat_ID": "a01",
 "certification": [ {
 "certification_type": "networking",
 "certification_company": "citrix","certification_name": "citrix",
 "certified_year": "1992",
 "certified_valitidy": "01/2014",
 "marks": "90",
 "comments": "sample",
 "skill_id": "En17"
  }]
}]

}
4

1 回答 1

0

尝试这个

<?php
$json = ' {

"_id":"employee_skill_doc",
"_rev":"269-e99377ad5d9e746a9d5b4777e7a50e46",
 "skills":[
 {
  "skill_name": "Dassault Simulia",
  "skill_id": "En17",
  "skill_set_id": "c03",
  "skill_set": "CAE (Computer Aided Engineering)",
  "skill_sub_ID": "b02",
  "skill_cat_ID": "a01"
 }],
 "certification":[
 {
  "certification_type": "networking",
  "certification_company": "citrix",
  "certification_name": "citrix",
  "certified_year": "1992",
  "certified_valitidy": "01/2014",
  "marks":"90",
  "comments":"sample",
  "skill_id": "En17"
 }]
 }';

 $arr = json_decode($json, true);
 $arr['skills'][0]['certification'] =  $arr['certification'];
 unset($arr['certification']);
 $json_new = json_encode($arr, JSON_PRETTY_PRINT);
 echo $json_new;
 ?>

输出 :

{
"_id":"employee_skill_doc",
"_rev":"269-e99377ad5d9e746a9d5b4777e7a50e46",
"skills":[
    {
    "skill_name":"Dassault Simulia",
    "skill_id":"En17",
    "skill_set_id":"c03",
    "skill_set":"CAE (Computer Aided Engineering)",
    "skill_sub_ID":"b02","skill_cat_ID":"a01",
    "certification":[
        {
        "certification_type":"networking",
        "certification_company":"citrix",
        "certification_name":"citrix",
        "certified_year":"1992",
        "certified_valitidy":"01\/2014",
        "marks":"90","comments":
        "sample","skill_id":"En17"
        }]
    }]
}

看演示

于 2014-09-04T06:23:28.920 回答