如何创建看起来像这个JSON文件的CSV文件

发布于 2025-02-03 08:44:06 字数 1145 浏览 3 评论 0原文

我基本上想为NFT游戏(Axie Infinity)更新多个学者。它需要一个看起来像这样的JSON文件:

{
        "name": "Scholar 1",
        "ronin": "ronin:<account_s1_address>",
        "splits": [
            {
                "persona": "Manager",
                "percentage": 44,
                "ronin": "ronin:<manager_address>"
            },
            {
                "persona": "Scholar",
                "percentage": 40,
                "ronin": "ronin:<scholar_1_address>"
            },
            {
                "persona": "Other Person",
                "percentage": 6,
                "ronin": "ronin:<other_person_address>"
            },
            {
                "persona": "Trainer",
                "percentage": 10,
                "ronin": "ronin:<trainer_address>"
            }
        ]
    }

但是,由于有多个学者/播放器,我想知道是否有任何CSV文件上的某些内容,如果我使用JSON工具将其转换或导入它,它将看起来像上面的JSON?

您的帮助非常感谢..谢谢!

PS:

第一行:

"name": "Scholar 1",
            "ronin": "ronin:<account_s1_address>",
            "splits":

需要重复,因为再次有多个学者,即学者1,Scholar 2,Scholar 3 ...

I am basically wanting to update multiple scholars for an NFT game (axie infinity). It requires a JSON file that looks like this:

{
        "name": "Scholar 1",
        "ronin": "ronin:<account_s1_address>",
        "splits": [
            {
                "persona": "Manager",
                "percentage": 44,
                "ronin": "ronin:<manager_address>"
            },
            {
                "persona": "Scholar",
                "percentage": 40,
                "ronin": "ronin:<scholar_1_address>"
            },
            {
                "persona": "Other Person",
                "percentage": 6,
                "ronin": "ronin:<other_person_address>"
            },
            {
                "persona": "Trainer",
                "percentage": 10,
                "ronin": "ronin:<trainer_address>"
            }
        ]
    }

But since there are multiple scholars/players, I wanted to know if there was anyway to format something on a CSV file that if I convert or import it using a JSON tool it will look like like the JSON above?

Your help is much appreciated.. Thank you!

PS:

The first lines:

"name": "Scholar 1",
            "ronin": "ronin:<account_s1_address>",
            "splits":

Would need to be repeated since again there are multiple scholars, i.e. Scholar 1, Scholar 2, Scholar 3...

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

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

发布评论

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

评论(2

后知后觉 2025-02-10 08:44:06

CSV文件结构是列基库,如果Axie Infinity需要JSON文件,则可以通过Excel或Google Sheet创建CSV文件,然后转换为JSON。

也有类似的答案可以将CSV转换为JSON

CSV file structure is column-base, if Axie infinity require JSON file, you can create a CSV file by Excel or Google sheet and convert to JSON.

there is a similar answer to convert CSV to JSON

傻比既视感 2025-02-10 08:44:06

starting from this CSV that has this structure

nameroninid_personapersona百分比split_ronin
Scholar 1ronin:&lt; councel_s1_address&gt;1经理44Ronin:&lt; Manager_Address&gt;
学者1ronin:&lt; councor_s1_address&gt;2学者40Ronin:&LT; Scholar_1_Address&gt;
学者1ronin:&lt; councor_s1_address&gt;3其他人6ronin:&lt; shot_person_address&gt;
学者1ronin:&lt; councor_s1_address&gt;4教练10Ronin:&lt; Trainer_Address&gt;

您可以运行此 miller 命令

mlr --c2j reshape -r "^(p|s)" -o k,v  then \
put '$k="splits".".".${id_persona}.".".$k' then \
cut -x -f id_persona then \
reshape -s k,v out.csv

[
  {
    "name": "Scholar 1",
    "ronin": "ronin:<account_s1_address>",
    "splits": [
      {
        "persona": "Manager",
        "percentage": 44,
        "split_ronin": "ronin:<manager_address>"
      },
      {
        "persona": "Scholar",
        "percentage": 40,
        "split_ronin": "ronin:<scholar_1_address>"
      },
      {
        "persona": "Other Person",
        "percentage": 6,
        "split_ronin": "ronin:<other_person_address>"
      },
      {
        "persona": "Trainer",
        "percentage": 10,
        "split_ronin": "ronin:<trainer_address>"
      }
    ]
  }
]

一些注释:

  • reshape -r“ (p | s)“ -ok,v,以将输入从宽到长;
  • put'$ k =“ splits”。“。”。$ {id_persona}。“。$ k',创建我将用作字段名称的值(splits.1) 。
  • ​删除字段id_persona;
  • 为宽度

reshape -sk,v,从长时间转换

+-----------+----------------------------+------------------+---------------------+-------------------------+------------------+---------------------+---------------------------+------------------+---------------------+------------------------------+------------------+---------------------+-------------------------+
| name      | ronin                      | splits.1.persona | splits.1.percentage | splits.1.split_ronin    | splits.2.persona | splits.2.percentage | splits.2.split_ronin      | splits.3.persona | splits.3.percentage | splits.3.split_ronin         | splits.4.persona | splits.4.percentage | splits.4.split_ronin    |
+-----------+----------------------------+------------------+---------------------+-------------------------+------------------+---------------------+---------------------------+------------------+---------------------+------------------------------+------------------+---------------------+-------------------------+
| Scholar 1 | ronin:<account_s1_address> | Manager          | 44                  | ronin:<manager_address> | Scholar          | 40                  | ronin:<scholar_1_address> | Other Person     | 6                   | ronin:<other_person_address> | Trainer          | 10                  | ronin:<trainer_address> |
+-----------+----------------------------+------------------+---------------------+-------------------------+------------------+---------------------+---------------------------+------------------+---------------------+------------------------------+------------------+---------------------+-------------------------+

。而不是使用它来创建最终的JSON输出

starting from this CSV that has this structure

nameroninid_personapersonapercentagesplit_ronin
Scholar 1ronin:<account_s1_address>1Manager44ronin:<manager_address>
Scholar 1ronin:<account_s1_address>2Scholar40ronin:<scholar_1_address>
Scholar 1ronin:<account_s1_address>3Other Person6ronin:<other_person_address>
Scholar 1ronin:<account_s1_address>4Trainer10ronin:<trainer_address>

you can run this Miller command

mlr --c2j reshape -r "^(p|s)" -o k,v  then \
put '$k="splits".".".${id_persona}.".".$k' then \
cut -x -f id_persona then \
reshape -s k,v out.csv

to have

[
  {
    "name": "Scholar 1",
    "ronin": "ronin:<account_s1_address>",
    "splits": [
      {
        "persona": "Manager",
        "percentage": 44,
        "split_ronin": "ronin:<manager_address>"
      },
      {
        "persona": "Scholar",
        "percentage": 40,
        "split_ronin": "ronin:<scholar_1_address>"
      },
      {
        "persona": "Other Person",
        "percentage": 6,
        "split_ronin": "ronin:<other_person_address>"
      },
      {
        "persona": "Trainer",
        "percentage": 10,
        "split_ronin": "ronin:<trainer_address>"
      }
    ]
  }
]

Some notes:

  • reshape -r "^(p|s)" -o k,v, to transform the input from wide to long;
  • put '$k="splits".".".${id_persona}.".".$k', to create values that I will use as field names (splits.1.persona,splits.1.percentage,splits.1.split_ronin,splits.2.persona,splits.2.percentage, ....
  • cut -x -f id_persona, to remove the field id_persona;
  • reshape -s k,v, to transform all from long to wide.

The real goal is to build, starting from that input, this kind of CSV

+-----------+----------------------------+------------------+---------------------+-------------------------+------------------+---------------------+---------------------------+------------------+---------------------+------------------------------+------------------+---------------------+-------------------------+
| name      | ronin                      | splits.1.persona | splits.1.percentage | splits.1.split_ronin    | splits.2.persona | splits.2.percentage | splits.2.split_ronin      | splits.3.persona | splits.3.percentage | splits.3.split_ronin         | splits.4.persona | splits.4.percentage | splits.4.split_ronin    |
+-----------+----------------------------+------------------+---------------------+-------------------------+------------------+---------------------+---------------------------+------------------+---------------------+------------------------------+------------------+---------------------+-------------------------+
| Scholar 1 | ronin:<account_s1_address> | Manager          | 44                  | ronin:<manager_address> | Scholar          | 40                  | ronin:<scholar_1_address> | Other Person     | 6                   | ronin:<other_person_address> | Trainer          | 10                  | ronin:<trainer_address> |
+-----------+----------------------------+------------------+---------------------+-------------------------+------------------+---------------------+---------------------------+------------------+---------------------+------------------------------+------------------+---------------------+-------------------------+

and than use it to create the final JSON output

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