Q:

gsheet importjson query for parsing JSONSchema

Using ImportJSON to parse JSONSchema documents and load into GSheet.
I have JSON documents with paths as in the snip below.
I want to output the names of properties in one column and the type in another.
Wanted to see if someone has done this already before i start hacking about with parseJSON or the defaultTransform functions of ImportJSON.
Added example GSheet here
Shows source, currently parsed output and what i need in terms of required output
/data/schema/properties/plan_id/type
/data/schema/properties/plan_id/maxLength
/data/schema/properties/plan_name/type
/data/schema/properties/plan_name/maxLength
/data/schema/properties/type/type
/data/schema/properties/type/maxLength
/data/schema/properties/quantity_ranges/type
/data/schema/properties/quantity_ranges/maximum
/data/schema/properties/quantity_ranges/minimum
/data/schema/properties/pricing_option/type
/data/schema/properties/pricing_option/maxLength
/data/schema/properties/currency/type
/data/schema/properties/currency/enum
/data/schema/properties/value/type
/data/schema/properties/value/maximum
/data/schema/properties/value/minimum

Thanks in advance!

A:

You want to achieve the following situation.

From

To

You want to achieve this using Google Apps Script.

I understood like above. If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Sample script:
When you use this sample script, please put =parseObject("SourceJSON!A1") to a cell in your shared Spreadsheet.
function parseObject(range) {
  var range = SpreadsheetApp.getActiveSpreadsheet().getRange(range);
  var value = range.getValue();
  var object = JSON.parse(value);
  var res = [];
  var headers = ["type", ["maxLength", "maximum"], "minimum", "enum"];
//  var headers = ["type", "maxLength", "maximum", "minimum", "enum"];
  for (var i in object.data.schema.properties) {
    var obj = object.data.schema.properties[i];
    for (var j = 0; j < headers.length; j++) {
      var temp = [object.data.id, object.data.version];
      if (Array.isArray(headers[j])) {
        for (var k = 0; k < headers[j].length; k++) {
          if (obj[headers[j][k]]) res.push(temp.concat([i, "",obj[headers[j][k]],"",""]));
        }
      } else {
      if (obj[headers[j]]) {
          var ar = [i, "","","",""];
          ar.splice(j + 1, 1, Array.isArray(obj[headers[j]]) ? obj[headers[j]].join(",") : obj[headers[j]]);
          res.push(temp.concat(ar));
        }
      }
    }
  }
  return res;
}

Result:

Note:

This sample script retrieves the data from the Spreadsheet.
In your DesiredOutput, the values of "maxLength" and "maximum" in the data are put to the same column. At above sample script, the result is the same with it. If you want to separate the values of "maxLength" and "maximum", please modify var headers = ["type", ["maxLength", "maximum"], "minimum", "enum"]; to var headers = ["type", "maxLength", "maximum", "minimum", "enum"];.
This sample script is for the value in your shared Spreadsheet. So when you use this for the data with other structure, an error might occur and/or the result you don't want might be returned. Please be careful this.

