public static JSONArray createStepIdArray(ArrayList<GuideStep> steps) throws JSONException {
    JSONArray jSteps = new JSONArray();
    for (GuideStep step : steps) {
      jSteps.put(jSteps.length(), step.getStepid());
    }

    return jSteps;
  }
  public static JSONObject createStepMediaJsonObject(GuideStep step) throws JSONException {
    JSONObject jMedia = new JSONObject();

    jMedia.put("type", "image");
    jMedia.put("data", createImageArray(step.getImages()));

    return jMedia;
  }
  public static GuideStep parseStep(JSONObject jStep, int stepNumber) throws JSONException {
    GuideStep step = new GuideStep(stepNumber);

    step.setGuideid(jStep.getInt("guideid"));
    step.setStepid(jStep.getInt("stepid"));
    step.setRevisionid(jStep.getInt("revisionid"));
    step.setOrderby(jStep.isNull("orderby") ? stepNumber : jStep.getInt("orderby"));
    step.setTitle(jStep.getString("title"));

    try {
      JSONObject jMedia = jStep.getJSONObject("media");
      String type = jMedia.getString("type");

      if (type.equals("image")) {
        JSONArray jImages = jMedia.getJSONArray("data");
        for (int i = 0; i < jImages.length(); i++) {
          step.addImage(parseImage(jImages.getJSONObject(i), null));
        }
      } else if (type.equals("video")) {
        JSONObject jVideo = jMedia.getJSONObject("data");
        step.addVideo(parseVideo(jVideo));
      } else if (type.equals("embed")) {
        JSONObject jEmbed = jMedia.getJSONObject("data");
        step.addEmbed(parseEmbed(jEmbed));
      }

    } catch (JSONException e) {
      Image image = new Image();
      step.addImage(image);
    }

    JSONArray jLines = jStep.getJSONArray("lines");
    for (int i = 0; i < jLines.length(); i++) {
      step.addLine(parseLine(jLines.getJSONObject(i)));
    }

    return step;
  }