英文:
Parse JSON using flatMap() in Google Sheet
问题
以下是您要翻译的部分:
我在Google表格的单元格中有以下的JSON结构:
[{"value":"example1@example.com","isPrimary":true},{"value":"example2@example.com","isPrimary":false}]
我想要实现的是将所有的值和isPrimary标志分开放在不同的列中,即:
example1@example.com | true | example2@example.com | false
使用以下Google Apps Script 没有生效:
const SAMPLE = value => [JSON.parse(value).result.flatMap((...))];
英文:
I have the following json structure in cells in a Google Sheet:
[{"value":"example1@example.com","isPrimary":true},{"value":"example2@example.com","isPrimary":false}]
What I want to achieve is that I have all values and isPrimary flags in separate columns, i.e.:
example1@example.com | true | example2@example.com | false
Google Apps Script using the following did not work:
const SAMPLE = value => [JSON.parse(value).result.flatMap((...))];
答案1
得分: 1
根据提供的信息,我看到您正在使用自定义函数。在您的应用脚本文件中,输入以下内容并保存更改:
const SAMPLE = val => [JSON.parse(val).flatMap(({value, isPrimary}) => [value, isPrimary])];
在您的表格中输入以下公式(将A1更改为包含JSON数据的单元格):
=sample(A1)
英文:
Based on the information provided, I see you're using a custom function. In your Apps Script file enter the following and save changes:
const SAMPLE = val => [JSON.parse(val).flatMap(({value, isPrimary}) => [value, isPrimary])];
In your sheet enter the following formula (change A1 to the cell where you have the JSON data):
=sample(A1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论