Is there an easy way to pretty print json from ins...
# box-products
r
Is there an easy way to pretty print json from inside commandbox? Sometimes
print.table
just won’t cut it. I have tried spelunking through comandbox-* repos, but I thought it may be faster to just ask
d
print.line(json) should do it. unless that aint pretty enough
👍 1
r
That is what I have currently and it works well enough
I do kinda dig the way the output is handled in
cfconfig show
d
Oh
r
Meh. I am just going down a rabbit hole. It isn’t required for what I am trying to do
Thanks Daniel
d
lol
well a rabbit into commandbox leads to finding some cool stuff. I have learned quite a bit about cfml by digging into how all the commandbox command work.
hey but for me print.line(json) looks like the output of config show.
r
Agreed… I don’t realize how ColdBox spoiled me until I need to read YAML from inside a commandbox custom command
d
message has been deleted
r
Hmm. Did I use another command
d
yaml? where are you finding that. I'm unaware of any yaml - lol. Have I completely missed something. hmmm.
I used print.line()
b
@Robert Zehnder It still baffles me how Adobe and Lucee have failed to add any built-in YAML support into CFML
That said, there is a module that's been around for a long time which will do YAML parsing for you
That said, I'm not really clear what you're asking for in regards to a better way to pretty print JSON. Can you maybe provide an example of what you'd like to see and how it differs from how CommandBox already prints structs and arrays
Formatting and color coding is pretty much the standard across any pretty print library I've seen
So I'd need to see an example of what else you'd like to see happen.
r
Honestly, it has more to do with my OCD. I am working on commandbox custom command to handle uploading articles to a database from a markdown file with frontmatter
b
I do kinda dig the way the output is handled in
cfconfig show
To be clear, there's nothing special about cfconfig show-- it's just defering to the print helper. You can get that same thing just by using
Copy code
print.line( randomCOmplexVarWhichHasArrayOrStructOrXML )
like @Daniel Mejia mentioned above
r
Ah, I forced it to a string. Might be my issue
b
Probalby, just pass the struct or array or XML right in!
d
yup
b
print.line()
is like
writeDump()
in that it will basically convert anything it can
r
bollocks
that fixed it
👍 1
smh
d
nice
b
Same with the
REPL
output
r
That makes life so much easier. Thanks guys
b
The one thing the print helper doesn't do is check strings to see if they are valid JSOn
I've thought about it, but it seems like it could get out of control and start formatting all sorts of random crap which was just meant to be a string!
😂 1
The print helper will check strings to see if they are XML, and format them, but that seemed like more of an edge case that was less likely to go awry
d
yeah don't brad. I actually output json as string in some cases where I just need the output so i can quickly copy paste from it.
r
I do love the table formatter
👍 1
b
The only exception is if the input is binary, I'll check it to see if it's JSON. I forget why exactly, but I had some specific use case once where it was handy 😆
I think I was playing with base64 encoded strings at the time
r
I did manage to shoehorn cbyaml into a commandbox command
modeled after how Luis did the commandbox-markdown module
b
Shouldn't need too much "shoe horning". Just include it as a dependency in the
box.json
!
Then you can inject the models via WireBox and you're off
Then when someone installs your command, cbyaml gets installed too as a nested dependency
r
I will have to try that out
Thanks again for all your help. 😄