discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to implement data from a JSON file

JR
jos.richters@visualdata.nl
Tue, Mar 31, 2026 8:13 AM

Hi there,

I am working on a (sort of) general scad in wich I need to present certain objects that are set up as either STL or SVG formats.

These files are stored in the same folder as the scad script.

Example:

ImportAnObject="Select a base object"; //[None,PerfectHeart_Outline.svg,DraadLamp_Model01_Raam.svg,DraadLamp1_Kanaal.svg,DraadLamp_Model01_FilledFrame.svg,RealityScan_Kruidnagel_HD_Model_Simple50K.stl,DefaultEgg.stl,DefaultEgg_Horizontal.stl,Paashaas.stl,Scad_SpechtFrame.stl,Scad_SpechtSilouette.stl,SpechtSilouette.svg,SpechtSilouette_V3.svg]

But I need to alter the scad script itself when I need to add a new object that hes to show in the drop-down in the customizer.

So I want to create a JSON file in wich the names of these objects are listed and then import this JSON as the source of the objectnames as: ImportAnObject=import("ObjectFileNames.json");

But I get an error/warning:

Compiling design (CSG Tree generation)...

WARNING: Failed to parse file 'E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects\ObjectFileNames.json': %s in file , line 195

Can somebody please help me out how to get this working with an example for this problem?

Thanks,

Jos.

Hi there, I am working on a (sort of) general scad in wich I need to present certain objects that are set up as either STL or SVG formats. These files are stored in the same folder as the scad script. Example: ImportAnObject="Select a base object"; //\[None,PerfectHeart_Outline.svg,DraadLamp_Model01_Raam.svg,DraadLamp1_Kanaal.svg,DraadLamp_Model01_FilledFrame.svg,RealityScan_Kruidnagel_HD_Model_Simple50K.stl,DefaultEgg.stl,DefaultEgg_Horizontal.stl,Paashaas.stl,Scad_SpechtFrame.stl,Scad_SpechtSilouette.stl,SpechtSilouette.svg,SpechtSilouette_V3.svg\] But I need to alter the scad script itself when I need to add a new object that hes to show in the drop-down in the customizer. So I want to create a JSON file in wich the names of these objects are listed and then import this JSON as the source of the objectnames as: ImportAnObject=import("ObjectFileNames.json"); But I get an error/warning: Compiling design (CSG Tree generation)... [WARNING: Failed to parse file 'E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects\\ObjectFileNames.json': %s in file , line 195](195,E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects/ArtVoronoi_BaseModel.scad) Can somebody please help me out how to get this working with an example for this problem? Thanks, Jos.
JB
Jordan Brown
Tue, Mar 31, 2026 11:41 AM

On 3/31/2026 1:13 AM, jos.richters--- via Discuss wrote:

So I want to create a JSON file in wich the names of these objects are
listed and then import this JSON as the source of the objectnames as:
ImportAnObject=import("ObjectFileNames.json");

You can import a JSON file for your program to operate on, and you're
doing it right.  But you cannot use a JSON file as the source of the
names in a Customizer drop-down, because those lists are not the result
of your program executing.

But I get an error/warning:

Compiling design (CSG Tree generation)...

WARNING: Failed to parse file
'E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects\ObjectFileNames.json':
%s in file , line 195
<195,E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects/ArtVoronoi_BaseModel.scad>

Can somebody please help me out how to get this working with an
example for this problem?

It's saying that it doesn't like your JSON file.  Unfortunately, there's
a bug in the error message that causes it to lose the exact error.

If you can send a copy of the JSON file, I'd be happy to take a look at
it and try to read it with an OpenSCAD with that bug fixed.

On 3/31/2026 1:13 AM, jos.richters--- via Discuss wrote: > > So I want to create a JSON file in wich the names of these objects are > listed and then import this JSON as the source of the objectnames as: > ImportAnObject=import("ObjectFileNames.json"); > You can import a JSON file for your program to operate on, and you're doing it right.  But you cannot use a JSON file as the source of the names in a Customizer drop-down, because those lists are not the result of your program executing. > But I get an error/warning: > > Compiling design (CSG Tree generation)... > > WARNING: Failed to parse file > 'E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects\ObjectFileNames.json': > %s in file , line 195 > <195,E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects/ArtVoronoi_BaseModel.scad> > > Can somebody please help me out how to get this working with an > example for this problem? > It's saying that it doesn't like your JSON file.  Unfortunately, there's a bug in the error message that causes it to lose the exact error. If you can send a copy of the JSON file, I'd be happy to take a look at it and try to read it with an OpenSCAD with that bug fixed.
JR
jos.richters@visualdata.nl
Tue, Mar 31, 2026 1:35 PM

The json file (test edition):

{

"fileFormatVersion": "1",

"parameterSets": {

"fileFormatVersion": "1",

    "BaseObjects": {

	"None",

	",PerfectHeart_Outline.svg"

	}

}

The json file (test edition): { "fileFormatVersion": "1", "parameterSets": { "fileFormatVersion": "1", "BaseObjects": { "None", ",PerfectHeart_Outline.svg" } }
RD
Revar Desmera
Tue, Mar 31, 2026 4:10 PM

On Mar 31, 2026, at 6:35 AM, jos.richters--- via Discuss discuss@lists.openscad.org wrote:


The json file (test edition):

{

"fileFormatVersion": "1",

"parameterSets": {

"fileFormatVersion": "1",

"BaseObjects": {

"None",

",PerfectHeart_Outline.svg"

}

}

I see 3 opening curly braces, but only 2 closing curly braces. Also, that comma inside the doublequote, just before PerfectHeart_Outline.svg looks suspicious.

-Revar

> On Mar 31, 2026, at 6:35 AM, jos.richters--- via Discuss <discuss@lists.openscad.org> wrote: > >  > The json file (test edition): > > { > > "fileFormatVersion": "1", > > "parameterSets": { > > "fileFormatVersion": "1", > > "BaseObjects": { > > "None", > > ",PerfectHeart_Outline.svg" > > } > > } > I see 3 opening curly braces, but only 2 closing curly braces. Also, that comma inside the doublequote, just before PerfectHeart_Outline.svg looks suspicious. -Revar
JR
jos.richters@visualdata.nl
Tue, Mar 31, 2026 8:34 PM

Hi Revar,

You are right. I fixed the braces but the error is still there….

Thanks, Jos.

Hi Revar, You are right. I fixed the braces but the error is still there…. Thanks, Jos.
JB
Jordan Brown
Tue, Mar 31, 2026 8:53 PM

[ Sigh.  I sent this early this morning, but for some reason it didn't
go out with the right From address. ]

Reformatted for readability:

{
"fileFormatVersion": "1",
"parameterSets": {
"fileFormatVersion": "1",
"BaseObjects": {
"None",
",PerfectHeart_Outline.svg"
}
}

Two problems:

  • Three open-braces, two close-braces.
  • BaseObjects is marked as an object with braces, but contains a list.

With the error handling fixed, it finds the second problem first:

WARNING: Failed to parse file
'C:/Users/Jordan/OneDrive/linux.home/openscad\junk.json':
[json.exception.parse_error.101] parse error at line 6, column 19:
syntax error while parsing object separator - unexpected ','; expected
':' in file ., line 1

PR#6745 is a fix for the JSON error message.

[ Sigh.  I sent this early this morning, but for some reason it didn't go out with the right From address. ] Reformatted for readability: > { > "fileFormatVersion": "1", > "parameterSets": { > "fileFormatVersion": "1", > "BaseObjects": { > "None", > ",PerfectHeart_Outline.svg" > } > } Two problems: * Three open-braces, two close-braces. * BaseObjects is marked as an object with braces, but contains a list. With the error handling fixed, it finds the second problem first: WARNING: Failed to parse file 'C:/Users/Jordan/OneDrive/linux.home/openscad\junk.json': [json.exception.parse_error.101] parse error at line 6, column 19: syntax error while parsing object separator - unexpected ','; expected ':' in file ., line 1 PR#6745 is a fix for the JSON error message.
JR
jos.richters@visualdata.nl
Thu, Apr 2, 2026 8:55 AM

Hi Jordan,

I installed the latest nightly build and tested the new error report. That works well:

WARNING: Failed to parse file 'E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects\ObjectFileNames.json': [json.exception.parse_error.101] parse error at line 6, column 9: syntax error while parsing object separator - unexpected ','; expected ':' in file ArtVoronoi_BaseModel.scad, line 190

Now looking for the solution of my function to read data from an external source.

Thanks for now.

Jos.

Hi Jordan, I installed the latest nightly build and tested the new error report. That works well: [WARNING: Failed to parse file 'E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects\\ObjectFileNames.json': \[json.exception.parse_error.101\] parse error at line 6, column 9: syntax error while parsing object separator - unexpected ','; expected ':' in file ArtVoronoi_BaseModel.scad, line 190](190,E:/3D_PotteryToVoronoids/5_Voronoid_Scad/ARTBaseVoronoiObjects/ArtVoronoi_BaseModel.scad) Now looking for the solution of my function to read data from an external source. Thanks for now. Jos.