title: How do I return an array of structs without flattening it in Solidity?
body: <p>I am trying to return an array of structs in solidity, <strong>but without flattening it</strong> .</p>
  <blockquote>
  <p>eg. desired results : 0:tuple(uint256,string,uint256)[]:
  {0,chris,9000},{1,yassin,6000}</p>
  </blockquote>
  <p>In the code below that i found <a href="https://gist.github.com/yassesh/d4572a9b7fb563509b7c7cdeb1a44b3f" rel="nofollow noreferrer">online</a>, i can return a list of struct that has been <strong>flattened</strong> :</p>
  <p><strong><code>getMembers()</code></strong></p>
  <blockquote>
  <p>0:tuple(uint256,string,uint256)[]: 0,chris,9000,1,yassin,6000</p>
  </blockquote>
  <pre><code>pragma solidity ^0.8.0;
  pragma experimental ABIEncoderV2;
  contract SavingsAccount {
    struct Member{
      uint id;
      string name;
      uint balance;
    }
    mapping (uint =&gt; Member) public members;
    event savingsEvent(uint indexed _memberId);
    uint public memberCount;
  
    constructor() public {
      memberCount = 0;
      addMember(&quot;chris&quot;,9000);
      addMember(&quot;yassin&quot;,6000);
    }
    function addMember(string memory _name,uint _balance) public {
      members[memberCount] = Member(memberCount,_name,_balance);
      memberCount++;
    }
    //return Single structure
    function get(uint _memberId) public view returns(Member memory) {
      return members[_memberId];
    }
    //return Array of structure Value
    function getMember() public view returns (uint[] memory, string[] memory,uint[] memory){
        uint[]    memory id = new uint[](memberCount);
        string[]  memory name = new string[](memberCount);
        uint[]    memory balance = new uint[](memberCount);
        for (uint i = 0; i &lt; memberCount; i++) {
            Member storage member = members[i];
            id[i] = member.id;
            name[i] = member.name;
            balance[i] = member.balance;
        }
  
        return (id, name,balance);
  
    }
    //return Array of structure
    function getMembers() public view returns (Member[] memory){
        Member[]    memory id = new Member[](memberCount);
        for (uint i = 0; i &lt; memberCount; i++) {
            Member storage member = members[i];
            id[i] = member;
        }
        return id;
    }
  }
  </code></pre>
  <p>Is there a way I can keep the an struct format inside the array of structs ?</p>