Do you use 3rd party libraries to validate json in...
# suitescript
i
Do you use 3rd party libraries to validate json input in restlet? If so can you share any links?
s
ajv works in suitescript
i
@Shawn Talbert How do you set up your Ajv? Mine throws error "ReferenceError: console is not defined". I used the latest version of ajv
s
you probably just need to define a
console
object
let me see if I made any notes on the topic
it's been a while since I did my POC but:
I proved that ajv version 7 works in SuiteScript 2.1 • Had to adjust paths ‘ajv’ -> ‘./ajv.min’ in compiled js • Tried standalone code generation but it doesn’t generate TS • Looked at type safe parsers but it only seems to work with JTD and that seems too early to work with. In fact, the module referenced in the example linked doesn’t even exist in the default ajv install (I.e. ‘ajv/dist/jtd’)
I wonder if JTD has evolved to be stable/popular at this point?
I didn't have any notes specific to
console
but it's not uncommon for me to have to add either a dummy
console
implementation or one that redirects to the NS
log
(or in my case, the NFT logger)
are you using SS 2.1?
actually, I did have this line of code that may be applicable:
Copy code
const ajv = new Ajv({logger:false}) // disable internal logging because it uses consoleoptions can be passed,
👍 1
so perhaps just turning off the internal logger was my workaround :)
👏 1
i
Yes, I am using 2.1. Your code above saved me. Thanks a lot.
👍 1