lundi 30 décembre 2019

expose array of objects elements inside the parent object in RAILS

I want to expose subBranches inside array of objects to the parent object as mentioned in Convert To section.

The actual array of objects is :

Original Data :

[
  {
    "ServiceTypeID": 3,
    "ChildCount": 0,
    "IsSelect": 0,
    "subBranches": [
      {
        "ServiceTypeID": 13,
        "ChildCount": 0,
        "IsSelect": 0
      },
      {
        "ServiceTypeID": 14,
        "ChildCount": 0,
        "IsSelect": 0
      },
      {
        "ServiceTypeID": 15,
        "ChildCount": 0,
        "IsSelect": 0
      }
    ]
  },

]

Convert to (basically expose subBranches to parent object):

This is the expected response :

[
  {
    "ServiceTypeID": 3,
    "ChildCount": 0,
    "IsSelect": 0,
    "subBranches":'',
    "ServiceTypeID": 13,
    "ChildCount": 0,       
    "IsSelect": 0,
    "ServiceTypeID": 14,
    "ChildCount": 0,
    "IsSelect": 0,
    "ServiceTypeID": 15,
    "ChildCount": 0,
    "IsSelect": 0
  }
]

How do I get This JSON?

Aucun commentaire:

Enregistrer un commentaire