JSFiddle - React, Tailwind, and code Playground

by Konstantin Cryman

HTML

<input id="fl" type="file">

JavaScript

const testInput = document.getElementById( 'fl' );

const saveFile = function( data   ){
        const __a = document.createElement( "a" );
        __a.href = URL.createObjectURL( new Blob( [ data ], { type: "application/json" } ) );
        __a.download = 'test_converted2.json';
        __a.click();
    }
    
const processJSON = ( json ) => {

  const { BASIS_LINE3D } = json.DOCUMENT.MODEL_SECTION;
  
  const finallyData = {};
      
  for( const nextLineData of BASIS_LINE3D ){

    finallyData[ nextLineData.NAMED_UUID._name ] = { p: [], e: [] };
  
    for( const nextPoint of nextLineData.GEOMETRY.GEO_POLYHEDRON3D.GEO_POINT_LIST_3D.GEO_POINT ){
      finallyData[ nextLineData.NAMED_UUID._name ].p.push( 
        parseFloat( nextPoint._x )
      )
      finallyData[ nextLineData.NAMED_UUID._name ].p.push( 
        parseFloat( nextPoint._y )
      )
      finallyData[ nextLineData.NAMED_UUID._name ].p.push( 
        parseFloat( nextPoint._z )
      )
    }
  
  	/*
    for( const nextPoint of nextLineData.GEOMETRY.GEO_POLYHEDRON3D.GEO_EDGE_LIST.GEO_EDGE ){
    finallyData[ nextLineData.NAMED_UUID._name ].e.push( [
    nextPoint._e1,    
    nextPoint._e2,
    ])
    }
    */
    
  }

	saveFile( JSON.stringify( finallyData ) );

}


testInput.addEventListener( 'change', () => {

	const fr = new FileReader();
  
  fr.onload = () => {
  	processJSON( JSON.parse( fr.result ) );
  }

	fr.readAsText( testInput.files[ 0 ] );

} );