I'm new to python and programming in general, asking for help: What to run in python code to print this data in multiple JSON files (300 files) that every file change the "name" line from #1 to #300 and the JSON files names will be like from 1.json to 300.json
is it possible?
{
"description": "#",
"image": "#",
"name": "#1",
"attributes": [
{
"trait_type": "#",
"value": "#"
}
]
}
namein the JSON snippet and then print it using the standard Python file API, e.g. in a loop over arange(1, 301)or the like. As a side note, it would be way easier to generate the files directly in Bash; simple file operations (redirections) are way shorter there than in Python, e.g.for ((i = 1; i <= 300; ++i)); do printf "${JSON_TEMPLATE}" "$i" > "${i}.json"; done. WhatJSON_TEMPLATEshould be is probably obvious (and it would have%dsomewhere in it to fill in the number).JSON_TEMPLATEvariable should have your JSON stuff assigned to it, verbatim, so e.g.JSON_TEMPLATE='{ ... name: "#%d", ... }'etc. (You can have newlines in quotes in Bash, no problem at all. (Or in Python you would use the'''/"""string literal type if you decide to go with Python. (Or, even better, a JSON-aware library, as someone already pointed out.)))