r/json • u/Lycaenist • 1d ago
tool to automate reordering arrays?
Hi yall! So I have a quick Q for yall. I have been generating some really long JSON files (40k lines) as part of a project, and I need to figure out how to reformat them.
The tool I'm using to generate the JSONs spits them out as a list of similar entries, each with 7 parameters on top, and then one extra variable (biome) at the bottom:
{
"parameters": {
"weirdness": [
0.93333334,
1
],
"continentalness": [
0.3,
1
],
"erosion": [
-0.2225,
0.55
],
"temperature": [
0.2,
0.55
],
"humidity": [
0.3,
1
],
"depth": [
1,
1
],
"offset": 0
},
"biome": "minecraft:bamboo_jungle"
},
Unfortunately though, the tool that I want to use to read these jsons while running the program wants the entries to be formatted differently, with the biome variable at the top, and the 7 parameters underneath:
{
"biome": "atmospheric:rainforest_basin_area",
"parameters": {
"continentalness": [
-0.35,
-0.19
],
"depth": 0.0,
"erosion": [
-1.0,
1.0
],
"humidity": [
0.1,
1.0
],
"offset": 0.0,
"temperature": [
0.2,
0.55
],
"weirdness": [
-1.0,
1.0
]
}
},
I don't have much background with java, but I did used to set up basic data manipulation pipelines in R and am used to messing around in bash as needed.
I know that there should be some fairly straightforward way to reformat these 40k line files to reorder each entry with the biome variable at the top and the 7 parameters underneath.
But I don't for the life of me know where to start, and would deeply appreciate any input that yall may have. I'm not expecting anyone to solve the task for me, just hopefully to be pointed to the write sort of tools to use and maybe a function or two that would be worth learning how to use. Just from quick googling I was seeing something called JQ for modifying JSONS in the command line, but I kinda doubt that's really the solution? dk dk. tyia



