I am trying to crate a react app to search flights(my recent interview).

User will select One Way/Return flights from the search component.

Below is the way I want to implement

An api will return list of all the flights where each object contains information about AirportName, Date, From , To

let flights = [
  {
    "AirportCode":"LAX",
    "AirportName":"Los Angeles",
    "from":"LAX",
    "to":"Austin",
    "Departure":"25 Jun 2019",
    "Arrival":"25 Jun 2019",
    "depTime":"1:05 AM",
    "arrTime":"2:05 AM"
  },
  {
    "AirportCode":"Aus",
    "AirportName":"Austin",
    "from":"Aus",
    "to":"LAX",
    "Departure":"25 Jun 2019",
    "Arrival":"25 Jun 2019",
    "time":"3:05 AM"
  },
  {
    "AirportCode":"CAL",
    "AirportName":"California",
    "from":"CAL",
    "to":"NY",
    "Departure":"15 Jun 2019",
    "Arrival":"15 Jun 2019",
    "time":"10:05 AM"
  }
]

If my api returns above format then I am assuming from the UI it will be easy to search the above json and display the results for both one way and two way results. For two way I have to query the JSON twice to look for object both sides.

With the above JSON structure I see there will be lot of conditions that I need to apply in code to search for oneway/return flights

Is the above JSON format a proper way to achieve this ? Is there a better approach for this ? Please suggest any references or a better JSON format

Comments (6)