如何编辑JSON数组?

发布于 2025-02-03 06:52:18 字数 419 浏览 2 评论 0原文

我想更改数组中的所有元素,删除我不需要的键,并为简单起见将名称变成键。你怎么做? 是否有一个简单的软件或网站,您可以在其中以这种方式编辑JSON数组?

我的意思是我想把这样的东西变成

"一": {
    "strokes": 1,
    "grade": 1,
    "freq": 2
},
"二": {
    "strokes": 2,
    "grade": 1,
    "freq": 9
}

这样的东西:

{
    "symbol":"一",
    "strokes": 1,
    "grade": 1
},
{
    "symbol": 二,
    "strokes": 2,
    "grade": 1
}

是的,您用什么工具来做类似的事情?

I want to change all elements in the array, deleting keys I do not need and also turning the names into keys for simplicity. How do you go about that?
Is there a simple piece of software or a website where you can edit JSON arrays in that manner?

What I mean is that I want to turn something like this:

"一": {
    "strokes": 1,
    "grade": 1,
    "freq": 2
},
"二": {
    "strokes": 2,
    "grade": 1,
    "freq": 9
}

Into something like this:

{
    "symbol":"一",
    "strokes": 1,
    "grade": 1
},
{
    "symbol": 二,
    "strokes": 2,
    "grade": 1
}

So yeah, what tool do you use to do something like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明天过后 2025-02-10 06:52:18

如果您要推荐推荐工具,那么问题是堆栈溢出的主题。

可以在一个JavaScript语句中轻松完成,因此这是您的工具:

const json = {
  "一": {
      "strokes": 1,
      "grade": 1,
      "freq": 2
  },
  "二": {
      "strokes": 2,
      "grade": 1,
      "freq": 9
  }
};

const result = Object.entries(json).map(([symbol, { strokes, grade }]) =>
  ({ symbol, strokes, grade }));

console.log(result);

If you're asking to recommend a tool, then the question is off-topic for Stack Overflow.

It can easily be done in one JavaScript statement though, so here's your tool:

const json = {
  "一": {
      "strokes": 1,
      "grade": 1,
      "freq": 2
  },
  "二": {
      "strokes": 2,
      "grade": 1,
      "freq": 9
  }
};

const result = Object.entries(json).map(([symbol, { strokes, grade }]) =>
  ({ symbol, strokes, grade }));

console.log(result);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文