Synthoid / ExportSheetData

Add-on for Google Sheets that allows sheets to be exported as JSON or XML.
MIT License
236 stars 46 forks source link

Any way to set first column a keys and second column as value #88

Open zestyhamburger opened 5 years ago

zestyhamburger commented 5 years ago

Was wondering if there is currently implemented way to export JSON with the first column being the key and the second (and so on) column(s) being the value. The purpose of this would be for localization where the first column list the unique id of the text string and the subsequent columns are values in different languages.

For example: UID | EN | ES | FR item_name | NameInEnglish | NameInSpanish | NameInFrench item2_name | Name2InEnglish | Name2InSpanish | Name2InFrench item3_name | Name3InEnglish | Name3InSpanish | Name3InFrench item4_name | Name4InEnglish | Name4InSpanish | Name4InFrench item5_name | Name5InEnglish | Name5InSpanish | Name5InFrench item6_name | Name6InEnglish | Name6InSpanish | Name6InFrench

This would be exported as: { "EN": { "item_name": "NameInEnglish", "item2_name": Name2InEnglish", "item3_name": Name3InEnglish", "item4_name": Name4InEnglish", "item5_name": Name5InEnglish", "item6_name": Name6InEnglish" } "ES": { "item_name": "NameInSpanish", "item2_name": Name2InSpanish", "item3_name": Name3InSpanish", "item4_name": Name4InSpanish", "item5_name": Name5InSpanish", "item6_name": Name6InSpanish " } "FR": { "item_name": "NameInFrench", "item2_name": Name2InFrench", "item3_name": Name3InFrench", "item4_name": Name4InFrench", "item5_name": Name5InFrench", "item6_name": Name6InFrench" } }

As you as see it is much more maintainable this way and readable since there will be many more rows than columns.

Synthoid commented 5 years ago

Hmm, the first column of each row is treated as the key for the whole row's contents. There are several ways you could export the data you desire by adjusting the format. In my experience, localization is best done with each row being localized so all the data on a given target is in the same area (basically the way you have it set up).

If you want your exported data to be grouped by language however, you can accomplish this a couple of ways:

  1. Use separate sheets for each language (ie the "EN" sheet has all the English localization)
  2. Use Nested Elements to position values

The first option is a much faster and easier way to export the data you want, so I would recommend that approach if it works for you.

SavedByZero commented 5 years ago

Yeah, I was also hoping to see a column-based objects instead of row-based, or at least an option to toggle between the two, but suggestion 1. above works as well. Thanks. Also, just a data point, but using the first column entry as the key for the row looks very messy sometimes, especially if the column entry is a sentence. I check the "Export Sheet Arrays" box because of this.

ErickXavier commented 2 years ago

Yeah, I'm trying that and is not working for me.

I have my table like this:

KEY,STRING
test_key,test
test_key_2,test 2

the desired export format would be:

{
  "test_key": "test",
  "test_key_2": "test 2"
}

bur it still exports as:

{
  "KEYS": "test_key_2",
  "ENGLISH": "test 2"
}

And this is my config:

{
  "exportType": "jsonFormat",
  "exportFolderType": "default",
  "exportFolder": "",
  "exportSheets": "currentSheet",
  "targetSheets": "{}",
  "replaceExistingFiles": false,
  "unwrapSingleRows": true,
  "collapseSingleRows": false,
  "ignoreEmptyCells": false,
  "ignoreColumnsWithPrefix": false,
  "minifyData": false,
  "includeFirstColumn": false,
  "ignorePrefix": "NOEX_",
  "unwrapSheetsWithPrefix": false,
  "unwrapPrefix": "US_",
  "collapseSheetsWithPrefix": false,
  "collapsePrefix": "CS_",
  "nestedElements": true,
  "forceArrayNest": false,
  "forceArrayPrefixNest": "NA_",
  "forceString": false,
  "exportCellArray": false,
  "exportSheetArray": false,
  "exportValueArray": false,
  "exportContentsAsArray": false,
  "exportCellObject": true,
  "emptyValueFormat": "string",
  "nullValueFormat": "null",
  "separatorChar": ",",
  "forceArray": false,
  "forceArrayPrefix": "KEYS",
  "exportChildElements": false,
  "exportBoolsAsInts": false,
  "rootElement": "data",
  "nameReplacementChar": "_",
  "includeDeclaration": false,
  "declarationVersion": "1.0",
  "declarationEncoding": "none",
  "declarationStandalone": "none",
  "forceAttributes": false,
  "attributePrefix": "ATT_",
  "forceChildElements": false,
  "childElementPrefix": "CE_",
  "forceInnerText": false,
  "innerTextPrefix": "IT_",
  "rootNamespace": "",
  "namespaces": []
}
ErickXavier commented 2 years ago

Was wondering if there is currently implemented way to export JSON with the first column being the key and the second (and so on) column(s) being the value. The purpose of this would be for localization where the first column list the unique id of the text string and the subsequent columns are values in different languages.

For example: UID | EN | ES | FR item_name | NameInEnglish | NameInSpanish | NameInFrench item2_name | Name2InEnglish | Name2InSpanish | Name2InFrench item3_name | Name3InEnglish | Name3InSpanish | Name3InFrench item4_name | Name4InEnglish | Name4InSpanish | Name4InFrench item5_name | Name5InEnglish | Name5InSpanish | Name5InFrench item6_name | Name6InEnglish | Name6InSpanish | Name6InFrench

This would be exported as: { "EN": { "item_name": "NameInEnglish", "item2_name": Name2InEnglish", "item3_name": Name3InEnglish", "item4_name": Name4InEnglish", "item5_name": Name5InEnglish", "item6_name": Name6InEnglish" } "ES": { "item_name": "NameInSpanish", "item2_name": Name2InSpanish", "item3_name": Name3InSpanish", "item4_name": Name4InSpanish", "item5_name": Name5InSpanish", "item6_name": Name6InSpanish " } "FR": { "item_name": "NameInFrench", "item2_name": Name2InFrench", "item3_name": Name3InFrench", "item4_name": Name4InFrench", "item5_name": Name5InFrench", "item6_name": Name6InFrench" } }

As you as see it is much more maintainable this way and readable since there will be many more rows than columns.

@zestyhamburger I found a CSV > JSON solution here: https://csvjson.com/csv2json Just remember to check HASH and TRANSPOSE.

Here an example: image