Convert JSON to Plain Text (useful to have LLM's analyse data from the DB)

Hi all,

I created this extension so that I can convert complex responses from the DB into plain text which I can then have ChatGPT / other LLM’s analyse.

JS file:
// JavaScript Document

const prettyjson = require('prettyjson');

exports.jsonToText = async function (options) {
    options = this.parse(options);
    let data = options.data;

    try {
        if (typeof data === 'string') {
            data = JSON.parse(data);
        }
    } catch (error) {
        throw new Error('Failed to parse data: ' + error.message);
    }

    const formattedData = prettyjson.render(data, {
        noColor: true,
        stringColor: null,
        keysColor: null,
    });

    return formattedData;
};

HJSON file:

{
    "type": "jsonToText",
    "module": "jsonToText",
    "action": "jsonToText",
    "groupTitle": "JSON Actions",
    "groupIcon": "fas fa-lg fa-code comp-data",
    "title": "JSON to Text",
    "icon": "fas fa-lg fa-code comp-data",
    "dataPickObject": true,
    "properties": [
        {
            "group": "Properties",
            "variables": [
                {
                    "name": "name",
                    "optionName": "name",
                    "title": "Name",
                    "type": "text",
                    "required": true,
                    "defaultValue": ""
                },
                {
                    "name": "data",
                    "optionName": "data",
                    "title": "data",
                    "type": "text",
                    "required": true,
                    "serverDataBindings": true
                }
            ]
        }
    ]
}

NPM you’ll need:

I won’t publish to NPM or maintain it as while it’s working for me now, i’m not confident in it being the perfect build of an extension.

1 Like

Same :sweat_smile:

1 Like