Hi,
how can i install and use that in my api Action?
I have seen the tutorial for custom extension - but i dont get it
Would be cool when you push me in the right direction.
I allready installed that with npm.
Hi,
how can i install and use that in my api Action?
I have seen the tutorial for custom extension - but i dont get it
Would be cool when you push me in the right direction.
I allready installed that with npm.
Well…the right direction is already documented as “creating custom extensions”. It’s not supposed to be a basic feature, but an advanced one.
We can guide you but we would need to know what have you tried and what didn’t work for you.
Start maybe by posting here the code you used in your hjson
and js
file.
ok. what i did so far was:
npm i jsonl
after that i created the folder.
This is the folder structure
and the file jsonl.js with that input:
const jsonl = require('jsonl');
exports.jsonl = jsonl;
as i seen in the youtube video it was for a model. do i also need the hjson file for a formatter?
in this thread they only created the slugify.js.
can you tell me what i need to put in my file so that i can select this via the wappler ui?
Or can you give me a tip where i can find the informations?
Thank you very much for your reply
Yes. You need an HJSON file for formatters too.
Here you are:
thanks
i have created the hjson and i see it in the ui. Now i have two files in the folder
jsonl.js und jsonl.hjson
{
type: 'method_jsonl',
groupTitle: 'Custom Formatters',
groupIcon: 'fa fa-lg fa-key',
addTitle: 'Add JSONL Formatter',
title: 'JSONL Formatter',
icon: 'fa fa-lg fa-file-code-o',
state: 'opened',
help: 'helptext',
properties: [
{
group: 'JSONL Properties',
variables: [
{
name: 'separator',
optionName: 'separator',
title: 'Separator',
type: 'text',
serverDataBindings: true,
defaultValue: '\n',
help: 'The separator to use between LDJSON objects.'
}
]
}
]
}
my jsonl.js looks like that
const jsonl = require('jsonl');
exports.jsonl = jsonl;
when i now try to use it my output is that:
> {"_readableState":{"highWaterMark":16384,"buffer":[],"length":0,"pipes":null,"pipesCount":0,"flowing":false,"ended":false,"endEmitted":false,"reading":false,"calledRead":false,"sync":false,"needReadable":true,"emittedReadable":false,"readableListening":false,"objectMode":false,"defaultEncoding":"utf8","ranOut":false,"awaitDrain":0,"readingMore":false,"decoder":null,"encoding":null},"readable":true,"_events":{},"_eventsCount":2,"_writableState":{"highWaterMark":16384,"objectMode":false,"needDrain":false,"ending":false,"ended":false,"finished":false,"decodeStrings":true,"defaultEncoding":"utf8","length":0,"writing":false,"sync":true,"bufferProcessing":false,"writecb":null,"writelen":0,"buffer":[],"errorEmitted":false},"writable":true,"allowHalfOpen":true,"_transformState":{"needTransform":false,"transforming":false,"writecb":null,"writechunk":null},"_destroyed":false}
What i can try now?
Now you need to perform all the logic in the js file as documented here
const jsonl = require('jsonl');
exports.method_jsonl = function(json) {
let formatted_json = {};
...
Use jsonl() API from Node package
...
return formatted_jsonl;
};
Then you would be able to use the formatter on a json value from Server Connect and it would return it.
Now you just need to figure out the jsonl()
code that goes in the formatter.
json
parameter of the method_jsonl
function contains the unformatted json you are applying the formatter to.
short update:
i have used your extension:
https://community.wappler.io/t/runjs-1-3-2/
and that code:
const data = csv;
const jsonl = data.map(item => JSON.stringify(item)).join('\n');
console.log(jsonl);
return jsonl;
that works perfect for me.
Thanks!
I’m really glad it was useful for you
Sometimes some quick scripting is better than building a full extension and that was why the RunJS extension was born.