I haven’t been bothered to write a full extension yet as my use cases are very simple and I just resort to write a few lines and use RunJS extension but I agree it would be useful if you could release an extension for this.
I’ll write a custom module and then post the GitHub repository in the extension channel which will include the HSJSON and JS files. I’m in the middle of writing two other custom modules as well. One for changing file permissions and one for running ssh commands on a remote server. So far it’s going well.
hi @tbvgl ,
If you’re using mysql, something like this might work for you.
You can check the JSON_OBJECT and JSON_ARRAYAGG functions in mysql.
Example 1 :
SELECT JSON_OBJECT
('address_id', address_id,
'address', address,
'address2', address2)
FROM location INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/location.json'
After the file is created here, it will be enough to move the file to the folder you want with the wappler functions.
PS : The example I have shown is a local example, you must specify a suitable path to your own server.
Example 2 :
SELECT
CONCAT("[",
GROUP_CONCAT(
CONCAT("{address_id:'",address_id,"'"),
CONCAT("address:'",address,"'"),
CONCAT(",address2:'",address2,"'}")
)
,"]")
AS json FROM location;
It won’t work for my case because I need a more flexible solution that allows formatting the content after getting a part of it from the db. Your use case will work for other people though.
I’m done with the wappler extension for writing files. I’ll test the error reporting a little more and then post the repo in the extension channel in the coming days. The extension will allow you to write any text content to any file format in any folder that you create before.