The Same JSON Structure but The Table is Different

Hello,
I’ve a problem …
I used the HTTPS Request Module to get a json file.
I want to generate a New JSON File with several informations from the original JSON file.
Before generate new JSON, i need to make calculations with the “Code” Module.
It’s javascript code. I used a table to push my data du JSON than i need. i used the “Push” function in javascript to complet my table. At the end, i return my table to get a new JSON.
My new JSON have same structure that JSON original. Buttt … The table view is different and i ve a probleme to used my new json with other module.
Just look my javascript code
Look both JSON Files
Look the table view both JSON Files
How to get the same table ? I try to used the list item module but i can’t find the solution.

My Code :

let BookID;
let RoomID;
let PlateForme;
let Nom;
let Prenom;
let DateCheckIn;
let DateCheckOut;
let NbrNuit;
let CABrut;
let Menage;
let CANette;

let Result;
let Tableau = [];

for (const item of $input.all()) {
  BookID = item.json.bookId;
  RoomID = item.json.roomId;
  PlateForme = item.json.referer;
  Nom = item.json.guestName;
  Prenom = item.json.guestFirstName;
  DateCheckIn = DateTime.fromISO(item.json.firstNight);
  DateCheckOut = DateTime.fromISO(item.json.lastNight).plus({days: 1});
  NbrNuit = DateCheckOut.diff(DateCheckIn, 'days').toObject();
  DateCheckIn = DateTime.fromISO(item.json.firstNight).toFormat('dd/LL/yyyy');
  DateCheckOut = DateTime.fromISO(item.json.lastNight).plus({days: 1}).toFormat('dd/LL/yyyy');
  NbrNuit = NbrNuit.days;
  Menage = 21;


  if (PlateForme=="Booking.com") {
    CABrut = (item.json.price)-(item.json.commission)-(item.json.invoice[2].price);
    CABrut = Math.round(CABrut*100)/100;
    }
  if (PlateForme=="Airbnb") {
    CABrut = parseFloat(item.json.price);
    }
  if (PlateForme=="justin.dautel") {
    CABrut = parseFloat(item.json.price);
    }
  if (CABrut==0) {
    CANette=0;
  }else{
    CANette = Math.round((CABrut-Menage)*100)/100;
  }


   Result = [{
    "BookId" : BookID,
    "RoomId" : RoomID,
    "Plateforme" : PlateForme,
    "Nom" : Nom,
    "Prenom" : Prenom,
    "DateCheckIn" : DateCheckIn,
    "DateCheckOut" : DateCheckOut,
    "NombreDeNuit" : NbrNuit,
    "CABrut" : CABrut,
    "CANette" : CANette,
   }];

    Tableau.push(Result);
}

return Tableau;

My WorkFlow :

Structure JSON :

View Table :

Can you help me please ?

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @justind1989, I am sorry you’re having trouble.

Unfortunately you only attached screenshots rather than the actual data. This makes it a bit hard for me to actually test out the behaviour and your transformation.

But it seems to me you are defining each Result as an array which you then push to another array Tableau. Perhaps in a first step you simply want to replace this:

   Result = [{
    "BookId" : BookID,
    "RoomId" : RoomID,
    "Plateforme" : PlateForme,
    "Nom" : Nom,
    "Prenom" : Prenom,
    "DateCheckIn" : DateCheckIn,
    "DateCheckOut" : DateCheckOut,
    "NombreDeNuit" : NbrNuit,
    "CABrut" : CABrut,
    "CANette" : CANette,
   }];

with something like this:

   Result = {
    "BookId" : BookID,
    "RoomId" : RoomID,
    "Plateforme" : PlateForme,
    "Nom" : Nom,
    "Prenom" : Prenom,
    "DateCheckIn" : DateCheckIn,
    "DateCheckOut" : DateCheckOut,
    "NombreDeNuit" : NbrNuit,
    "CABrut" : CABrut,
    "CANette" : CANette,
   };

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.