cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Could not get the json data in particular format

I want to display nodes and their relationship in particular format

[
{
'ID' : 1,
'VM_CODE' : '',
'VIRTUAL_MACHINE': '',
'OPERATING_SERVICE': '',
'SIZE' : '',
'CPU' : '',
'Memory' : '',
'Disks' : '',
'SERVICE_NAME' : '',
'SERVICE_CODE' : '',
'TASK_MEMORY' : '',
'TASK_CPU' : '',
'ENV_CODE' : '',
'ENV_PORT_NO' : '',
'SERVICE_PORT_NO' : '',
'SERVICE_PORT_ID' : '',
'TASK_TYPE' : '',
'PARENT_ID' : 0
}]

 

but after executing this code I am getting data in different format

code-

session
  .run('match(n:VM) optional match (n)-->(p:Storages) optional match (n)-->(m:dockercomposer) optional match (n)-->(m)-->(o) with n as node, collect(properties(p)) as Storage, collect(properties(m)) as Service,collect(properties(o)) as ServiceDetail return {node: node, Storage:Storage, Service:Service, ServiceDetail:ServiceDetail} as json')  
  .then(function (result){
    var sampleArr =[];
    result.records.forEach(function(record){
        sampleArr.push({
            id: record._fields[0].identity.low,
            VM_CODE: record._fields[0].properties.VM_CODE,
            VIRTUAL_MACHINE: record._fields[0].properties.VIRTUAL_MACHINE,
            OPERATING_SERVICE: record._fields[0].properties.OPERATING_SERVICE,
            SIZE: record._fields[0].properties.env,
            CPU: record._fields[0].properties.CPU,
            Memory: record._fields[0].properties.Memory,
            Disks: record._fields[0].properties.Disks,
            SERVICE_NAME: record._fields[0].properties.SERVICE_NAME,
            SERVICE_CODE: record._fields[0].properties.SERVICE_CODE,
            TASK_MEMORY: record._fields[0].properties.TASK_MEMORY,
            TASK_CPU: record._fields[0].properties.TASK_CPU,
            ENV_CODE: record._fields[0].properties.ENV_CODE,
            ENV_PORT_NO: record._fields[0].properties.ENV_PORT_NO,
            SERVICE_PORT_NO: record._fields[0].properties.SERVICE_PORT_NO,
            SERVICE_PORT_ID: record._fields[0].properties.SERVICE_PORT_ID,
            TASK_TYPE: record._fields[0].properties.TASK_TYPE,
            PARENT_ID: record._fields[0].properties.PARENT_ID,

    });
  });

  res.json({
    sample :sampleArr,
  });
})
.catch(function (err) {
  console.log(err);
});
});
 
 
I want data in such a format that is displayed in the picture
somiya12_0-1662737448583.png

in this 4 is a node and 5,6,7,8, are the relations of it if data exist then it should display otherwise blank

the data should be in this format-->

[
    {
        'ID' : 1,
        'VM_CODE'  : 'DS3_v2_1',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': 'Linux',
        'SIZE' : 'Standard_DS3_v2',
        'CPU' : '4',
        'Memory' : '14 GiB',
        'Disks'  : 3,
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : '',
        'TASK_MEMORY' : '',
        'TASK_CPU'  : '',
        'ENV_CODE' : '',
        'ENV_PORT_NO' : '',
        'SERVICE_PORT_NO' : '',
        'SERVICE_PORT_ID' : '',
        'TASK_TYPE' : '',
        'PARENT_ID' : 0

    },
   
    {
        'ID' : 4,
        'VM_CODE'  : 'D2s_v3_12',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': 'Linux',
        'SIZE' : 'Standard_D2s_v3',
        'CPU' : '2',
        'Memory' : '8 GiB',
        'Disks'  : 2,
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : '',
        'TASK_MEMORY' : '',
        'TASK_CPU'  : '',
        'TASK_TYPE' : '',
        'PARENT_ID' : 0

    },
    {
        'ID' : 5,
        'VM_CODE'  : '',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': '',
        'SIZE' : '',
        'CPU' : '',
        'Memory' : '',
        'Disks'  : '',
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : 'MDB426',
        'TASK_MEMORY' : '128',
        'TASK_CPU'  : '128',
        'TASK_TYPE' : '',
        'PARENT_ID' : 4
    },
    {
        'ID' : 6,
        'VM_CODE'  : '',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': '',
        'SIZE' : '',
        'CPU' : '',
        'Memory' : '',
        'Disks'  : '',
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : 'JGR121',
        'TASK_MEMORY' : '128',
        'TASK_CPU'  : '128',
        'TASK_TYPE' : '',
        'PARENT_ID' : 4
    },
    {
        'ID' : 7,
        'VM_CODE'  : '',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': '',
        'SIZE' : '',
        'CPU' : '',
        'Memory' : '',
        'Disks'  : '',
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : 'INSVC',
        'TASK_MEMORY' : '128',
        'TASK_CPU'  : '128',
        'TASK_TYPE' : '',
        'PARENT_ID' : 4
    },
    {
        'ID' : 7,
        'VM_CODE'  : '',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': '',
        'SIZE' : '',
        'CPU' : '',
        'Memory' : '',
        'Disks'  : '',
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : 'INSVC',
        'TASK_MEMORY' : '128',
        'TASK_CPU'  : '128',
        'TASK_TYPE' : '',
        'PARENT_ID' : 4
    },
    {
        'ID' : 8,
        'VM_CODE'  : '',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': '',
        'SIZE' : '',
        'CPU' : '',
        'Memory' : '',
        'Disks'  : '',
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : 'TMPMS',
        'TASK_MEMORY' : '128',
        'TASK_CPU'  : '128',
        'TASK_TYPE' : '',
        'PARENT_ID' : 4
    },
    {
        'ID' : 9,
        'VM_CODE'  : 'D2s_v3_12',
        'VIRTUAL_MACHINE': '',
        'OPERATING_SERVICE': 'Window',
        'SIZE' : 'Standard_D2s_v3',
        'CPU' : '2',
        'Memory' : '8 GiB',
        'Disks'  : 2,
        'SERVICE_NAME' : '',
        'SERVICE_CODE' : '',
        'TASK_MEMORY' : '',
        'TASK_CPU'  : '',
        'TASK_TYPE' : '',
        'PARENT_ID' : 0

    }
]
 
 
It will be better if instead of modifying query, code would be modified
1 REPLY 1

It looks like a single VM has multiple services running on it.  Do you want to have a row for each service and have the VM details repeat for each service?  If a VM has zero services, then have a row for that VM, but have null values for the service properties? 

Can you provide the properties for each entity?  What does you output look like now? Which driver language is your code from?