#include <Arduino_JSON.h>


char k[10][10];
int v[10];


void valueExtractor() {

  Serial.println("object");
  Serial.println("======");
  JSONVar obj;

  // Making a JSON Object
  obj["type"] = "hsv";
  obj["strip"]= 2;
  obj["hue"] = 66;
  obj["sat"] = 25;
  obj["val"] = 214;
  // obj["jok"]["hij"] = "bar";

  Serial.println(obj);
  Serial.println();
  Serial.println("Extracted Values");
  // Serial.println("======");

  objRec(obj);

}

void objRec(JSONVar obj) {
  // Serial.println("{");
  Serial.print("JSON Type: ");
  Serial.println(JSON.typeof(obj));

  String type = obj["type"];
  Serial.println(type);

  if (type == "hsv") {
    v[0] = obj["strip"];
    v[1] = obj["hue"];
    v[2] = obj["sat"];
    v[3] = obj["val"];
;  }

  Serial.print("Strip: ");
  Serial.println(v[0]);

  Serial.print("HUE: ");
  Serial.println(v[1]);
  
  Serial.print("SAT: ");
  Serial.println(v[2]);
  
  Serial.print("VAL: ");
  Serial.println(v[3]);

  JSONVar keys = obj.keys();
  JSONVar values;

  // for (int x = 0; x < obj.keys().length(); x++) {

  //   strcpy(k[x], obj.keys()[x]);
  //     Serial.print("K = ");
  //     Serial.println(k[x]);
    
  //   values = obj[keys[x]];
  //     Serial.print("Values = ");
  //     Serial.println(values);
    
  // }
  
  
  
  
    // Checks for an object and moves to the next item
    // Calls back to itself witht he next item
    // Checks again if the item is an object
    // if ((JSON.typeof(obj[obj.keys()[x]])).equals("object")) {
    //   k[x] =  (String)obj.keys()[x];
    //   Serial.print("Key "); 
    //   Serial.print(x);
    //   Serial.print(" = ");
    //   Serial.print(k[x]);
    //   // Serial.print(obj.keys()[x]);
    //   Serial.println(" : ");
      
    //   // Serial.println("Step 2");
    //   objRec(obj[obj.keys()[x]]);
    // }
    // // If the item is not an object the function extracts the value
    // else {
    //   Serial.println("Step 2");
    //   Serial.print(obj.keys()[x]);
    //   Serial.print(" : ");

    //   // Serial.println("Step 4");
    //   Serial.println(obj[obj.keys()[x]]);

  }
  // Serial.println("}");



void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial);
  valueExtractor();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation
}