#Visualize JSON with Typescript
1 messages ยท Page 1 of 1 (latest)
<@&987246964494204979> please have a look, thanks.
import "jjsontree.js/src/ts/api.ts";
import "jjsontree.js/dist/jsontree.js.min.css";
import "jjsontree.js";
window.$jsontree.render(document.getElementById("app")!, {
data: {
hey: "there",
you: [1, 2, 3, 4],
},
});
Not the most beautiful thing in the world
but the api.ts file contains only type declarations
For some reason they do not put those in the d.ts files which are made for this purpose
cool. im currently running another include version, results in a second
well, at least it shows sth
its spamming this one
ill retry with ur imports now, minute
And you might want to cast the types
import { BindingOptions } from "jjsontree.js/src/ts/type.ts";
window.$jsontree.render(document.getElementById("app")!, {
data: {
hey: "there",
you: [1, 2, 3, 4],
},
} as BindingOptions);
Don't ask me why that is not the default type for it
But then you can auto-complete the options
Yea, just throw it in there too, I guess
TS5097: An import path can only end with a .ts extension when allowImportingTsExtensions is enabled.
is that in the package.json? i cant find it
or can i just import { BindingOptions } from "jjsontree.js/src/ts/type"; instead
No idea, that sounds like build system stuff
oh frick
is it one of these things that works in firefox but not in my custom game cef thing
๐
yeah but not in this one i guess
Apparently
lmao
So you either patch out intl support (or monkey-patch your own Intl)
Or you use sth else
lets try this guy instead
JSON2HTML is a lightning fast client side javascript HTML templating library for both jQuery and Node.js.
i feel like i was very close to getting it working
ill set it up quickly
so, sniping from their website the vanilla js code to get it working is:
var _visualizer = new visualizer($("#visual-tab"));
_visualizer.visualize(json);
their definition for this is some weird js prototype thing
instead of a proper class/module or whatever
wait, here is the source: https://github.com/moappi/visualizer.json2html/blob/master/lib/visualizer.js
so
ill try with this
And where is the problem?
import "../visualizer/visualizer.css"
import "../visualizer/visualizer.js"
"allowJs": true
and this guy
lets see what happens
last time i had different imports and tried to declare the type
and then it said it cant find the visualizer
Surely works 
You can put that png in the public folder
public folder? whats that
i.e. for public static resources
ill try it with that
that other css there works
so perhaps telling it to load it like that will work as well
it smells like a more vanilla style load
:D
It likely won't serve the image though, but the 404 on the image might be acceptable
ill be happy if it just works
its just for internal debugging
protip: dont ever mention to ur boss that u have some frontend knowledge
xD
would have been too nice
so yeah, this line here fails const json_visualizer = new visualizer(node);
If that is a proper module, you can assign the result of the import a name?
yeah, i could patch the source into sth working
i suppose
problem is that im not comfortable enough with the source
Slap an export before that and save it as a .js file and you should be done, I guess
ive never done this, do u have it at hand somewhere?
function visualizer($node) {
-> export function visualizer
what i dont understand is, why do we write new visualizer(...)
its a function isnt it
why new
Basically it creates a "class" out of it, using it as the constructor
Old old style
and is that compatible with typescripts new?
cause im technically writing typescript
like, this is from their js-only website:
which im trying to mimic
but im in ts
I wonder if Copilot can translate that file xD
Yea, but that seems to fail at the type check
import { visualizer} from "../visualizer/visualizer.js";
i really have no problem rewriting the visualizer.js. i just struggle understanding this non-common way of doing js
like they have this function-style object
and then slap methods on it via prototype or sth
ill try to add a helper function
To be quite honest, writing that debugger thing yourself sounds easier
There is details in HTML which gives you collapsible content for free
Prototype inheritance is quite nice sometimes. You also find that in Lua, I think
Or you use that with any, but it also seems to use jquery?
Not in a raw new project afaik
i meant in the one this json thing relies on, which is node-json2html
Ah, maybe
its the underlying base api. their actual product
for which the visualizer is just a demo
๐
so possibly it could be hacked out. just not sure how to do this
class Collator {
function compare(a: string, b: string) -> number {
return a.localCompare(b);
}
}
window.Intl = {
Collator: Collator
}
might be enough
made progress
my ts call now goes into the js
but crashes here
smells like its aaaalmost done
๐
ive added this guy here as vanilla js entry point
and thats what im invoking in ts now
perhaps the node im passing is the wrong type
yeah i think they expect it to be a jquery node
yeah its full of it
ill try to patch it to $(base.node)
or just pass in a jquery node at the start?
Yea
fingers crossed it actually has jquery somewhere down the line
seriously these amateurs cant produce proper libs for people to use

okay. im out of time for today
sorry to end it on SUCH a cliffhanger haha
I think you either monky-patch intl or you build your own (or find a different one)
ill add jquery tomorrow and then report back
๐ฌ
In the time you spent getting it to work you could have written three crude libraries already!!
hehe
its just not a nice environment to produce new content in, having to wait 10min on each edit.
would have to move it out into some more traditional website demo before i integrate it into the real thing
@gilded furnace
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure ๐
progress. im still battling with the visualizer
it seems its using a jquery version of the json2html library
which isnt compatible with the node.js variant
lol
but ive now just copy pasta all dependencies straight into the js file
that is, the jquery.min
and json2html.min
all in one file
and now its doing sth
looks like only the css is missing now
its definitely there now
but its not updating itself in-place so i probably need to add a refresh button or sth
which is annoying cause i cant view it expanded live then
i also had to replace some deprecated jquery they were using, lol
๐
Ay
time to blast some big json into it and see if i even have a scrollwheel, LOL
Watch yourself rewrite this with virtual scrolling in a minute
;_;
search function would also be nice
seriously. we already have all this debugging stuff working with IMGUI for another environment we had to work with.
the sad part is that this environment has imgui as well but doesnt expose it
so now i have to rewrite the existing debugging stuff as website
yeah
i mean, its embedded into a game. its rendered on some ingame "tablet" thing
im glad it even supports mouse clicking out of the box
Oh well
Sounds great
ctrl+f doesn't sound too easy, but expanding everything and then using ctrl+f might be fast enough
browsers are surprisingly good at rendering text
the good thing is that i dont expect us doing heavy debugging sessions in that environment anyways. we have the other environment with working and existing debugging tools. so if sth is wrong with our logic we would debug it there instead.
for this one its acceptable if its a bit bare bones
as long as i can inspect all data
frick. no scrollwheel out of the box. but another page on the tablet has scrollwheel. so perhaps its just the css
this one has a scrollwheel
overflow-y:auto works
๐
okay great. stuff seems to be working good enough now
thank you very much guys ๐
@gilded furnace
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure ๐
great... guess what
oh no
the game hard crashes the moment i do JSON.parse(dataString) when i send the real data
its 977000 chars long. so about 1 MB

just write your own shit at this point lmao
i mean if JSON.parse from JS itself crashes then ill have trouble working with the data
ah yeah makes sense
i probably have to look into splitting it into chunks on the data level itself
which is annoying
but you sure that javascripts own JSON.parse breaks with 1MB?
I doubt you are the first one to parse bigger jsons
google says the limit is usually at around 2-4 MB. but im also not running on a normal browser
so perhaps it has smaller limits
thats crazy