<@UAQQBHBPV> I've had a lot of success with this: ...
# suitescript
t
@Ben VanderBeek I've had a lot of success with this: https://github.com/bojanbjelic/xml2json/ You can find more info here: https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/
👍 2
b
to be clear, you're saying you used this in server side suitescript (user event, scheduled, etc)?
t
I've used it to do transformations - but not in SuiteScript. The directions that he lists in the blog post for doing the transformation in JS should work.
It took me forever to find a decent XSLT that was reliable. This one is.
b
got it. thanks so much for your input on this.
the javascript example in the link is inside the browser and seems to use browser-specific functions that wouldn'e be available in server-side suitescript, e.g.
window.DOMParser
t
No problem. If you need help, let me know. Getting this to work was a huge deal for me. I do a lot of custom API work using Xojo, and that's where I've used it.
Ahhh...
I see.
If it will help, I can prop up a quick API that you could post a SOAP request to, and return back JSON to you.
b
aw thanks! probably need to find a solution that can be self-contained, otherwise would gladly take you up on your offer
similar to the problem i had with https://github.com/abdmob/x2js, it errored in the SuiteScript debugger with useless error information.
t
I wonder if you could whip something up in Node? I think it's really just a matter of finding something that can do XML transformations.
b
yeah that makes sense. unfortunately the need here is to do this in suitescript, without dependencies on external services.
t
I see.
b
i've seen it done, just would prefer to use a more stable json->XML library rather than write my own
anyway really appreciate your ideas on this.
t
No problem. I just looked at the NetSuite XML module, and it doesn't seem to support transformations, which is surprising.
If you do find a way to handle this natively, please let me know.
m
@Ben VanderBeek I was recently looking for the same thing, you cant use these library's in Suitscript because its server side. Im still looking for a good solution.
you can probably hook it up to some node api. not the ideal solution.
b
for anyone curious, after some minor tweaks (mostly removing lines 18 - 32), it turns out this line (https://github.com/abdmob/x2js/blob/master/xml2json.js#L386) is what was causing the debugger to provide unexpected error with no error message. once i removed
<![CDATA["+jsonTxtObj.__cdata+"]]>
, it ran fine.