title: How to collate an array of JSON objects by a property into a struct containing vectors of each object's properties?
body: <p>I am receiving a stream of sensor data which I need to aggregate and perform basic statistics on (average, max, min, etc.). There are multiple values but the sensor data can be inconsistent and some of the values can be missing. </p>
  
  <p>From reading the book, it seems like <code>Option</code> should be used when the values of <code>luminosity</code> or <code>color</code> are missing but I am confused about this.</p>
  
  <p>This is an example of my sensor data:</p>
  
  <pre><code>[
      {
          "sensor": "left",
          "luminosity": "50",
          "color": "(255,0,0)"
      },
      {
          "sensor": "left",
          "color": "#0f0"
      },
      {
          "sensor": "right",
          "luminosity": "20"
      },
      {
          "sensor": "right",
          "luminosity": "40",
          "color": "(255,0,0)"
      },
      {
          "sensor": "left",
          "luminosity": "30"
      },
      {
          "sensor": "top",
          "luminosity": "10"
      },
      {
          "sensor": "right",
          "color": "(0,0,0)"
      }
  ]
  </code></pre>
  
  <p>Each sensor's data will be stored in an instance of the following struct:</p>
  
  <pre><code>struct Data {
      pub luminosity: Vec&lt;String&gt;,
      pub color: Vec&lt;String&gt;,
  }
  </code></pre>
  
  <p>I want to iterate over the above JSON object, match the sensor to the correct struct instance ("right" sensors to the "right" sensor struct) and push the contents of each JSON observation onto the vectors (inside each struct instance).</p>
  
  <p>Missing values need to be recorded so that for each "observation" there is one push action for every vector in the struct for the corresponding sensor's struct instance.</p>