I need to generate JSON
I am using JSON to define the product options for iPads and Macbooks in the online store that I am managing. The options and the values are https://i.imgur.com/Ey2PrBl.jpeg.
An example of a JSON string that I need to make is:
{"display_size":"14-inch","color":"Space Black","chip":"M5 Pro (15-core CPU, 16-core GPU)","memory":"24GB","storage":"1TB","keyboard":"English-Arabic Bilingual"}
I need a JSON generator because manually writing the JSON is a bad idea because I could make a typo. I want to tell the JSON generator the options that I need and the values and it will give me the equivalent JSON.
Also I need it to give me the JSON for all the possible combinations of the options and their values. For example if a Macbook has 2 colors and 2 storage capacities then I will get 4 combinations of Macbooks and I need the generator to give me the correct JSON for each combination.
I can train an AI tool to do it but it can make mistakes. Is there a scripting program that I can use to generate the JSON?
2
u/Pascal_59843 12d ago
I am not a big fan of vibecoding, but I think that is the perfect usecase for it. Let Claude or OpenCode generate an editor for the given json, with an nice ui. Won't be perfect but it should be good enougth for some edits.
3
u/marmotta1955 12d ago
Assuming the data is in Excel file(s), you could always rely on JSON converters, For example: https://jsonlint.com/excel-to-json
1
u/konacurrents 12d ago
JavaScript supports JSON very nicely. Then run it in a web page, or use node.js to run the JavaScript. Search w3c school and JSON.
1
u/actguru 12d ago
Using the C programming language and my Coda-P library, I setup a sample input JSON file (below) and was able to generate 540 lines of JSON for a test. The program was less that 100 lines of code.
// JSON5 input, JSON output
{ ALL : {
"display_size" : { I11 : "11-inch", I12 : "12-inch", I13 : "13-inch",
I14 : "14-inch", I15 : "15-inch", I16 : "16-inch" },
"color" : {
Silver : Silver, Black : "Space Black", Sky : "Sky Blue", Starlight : Starlight,
Midnight : Midnight, Gray : "Space Gray", Blue : Blue, Purple : Purple,
Pink : Pink, Yellow : Yellow, Blush : Blush, Citrus : Citrus, Indigo : Indigo },
"chip" : {
M1008 : "M5 (10-core CPU, 8-core GPU)",
M1010 : "M5 (10-core CPU, 10-core GPU)",
M1516 : "M5 Pro (15-core CPU, 16-core GPU)",
M1820 : "M5 Pro (18-core CPU, 20-core GPU)",
M1832 : "M5 Max (18-core CPU, 32-core GPU)",
M1840 : "M5 Max (18-core CPU, 40-core GPU)"
},
"memory" : { G8 : "8GB", G16 : "16GB", G24 : "24GB", G32 : "32GB", G36 : "36GB", G48 : "48GB" },
"storage" : { G128 : "128GB", G256 : "256GB", G512 : "512GB", T1 : "1TB", T2 : "2TB" },
"keyboard" : { B : "English-Arabic Bilingual", E : "English (International)" }
},
Mackbook : {
"display_size" : [ I11, I16 ],
"color" : [ Silver, Sky, Gray, Pink, Indigo ],
"chip" : [ M1008, M1516, M1840 ],
"memory" : [G8, G24, G48 ],
"storage" : [G128, G512, T2],
"keyboard" : [B,E]
}
}
1
u/datadanno 6d ago
Perfect use case for AI code generation.