• dump all object keys/values

    From Mortifis@VERT/ALLEYCAT to All on Wednesday, April 08, 2020 01:42:22
    How would one show all of the key/values for http_request.query?

    Thanks,

    ~Mortifis

    ---
    ¡ Synchronet ¡ AlleyCat! BBS Lake Echo, NS Canada
  • From echicken@VERT/ECBBS to Mortifis on Wednesday, April 08, 2020 00:53:42
    Re: dump all object keys/values
    By: Mortifis to All on Wed Apr 08 2020 01:42:22

    How would one show all of the key/values for http_request.query?

    Object.keys(http_request.query).forEach(function (e) {
    writeln(e + ': ' + JSON.stringify(http_request.query[e]));
    });

    Because each property of http_request.query is an array, I'm JSON.stringifying the value to dump the array contents.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    ■ Synchronet ■ electronic chicken bbs - bbs.electronicchicken.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Wednesday, April 08, 2020 09:01:03
    Thank you, very much ... I was close but no cigar .. take care & stay safe

    ~Mortifis

    ---
    ¡ Synchronet ¡ AlleyCat! BBS Lake Echo, NS Canada
  • From Nightfox@VERT/DIGDIST to Mortifis on Wednesday, April 08, 2020 12:29:04
    Re: dump all object keys/values
    By: Mortifis to All on Wed Apr 08 2020 01:42 am

    How would one show all of the key/values for http_request.query?

    To print out the key/values of an object, I usually like to do this (this example assumes it's being run on the telnet terminal:

    for (var prop in http_request.query)
    console.print(prop + ": " + http_request.query[prop] + "\r\n"); console.pause();

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Wednesday, April 08, 2020 12:59:40
    Re: dump all object keys/values
    By: Nightfox to Mortifis on Wed Apr 08 2020 12:29 pm

    Re: dump all object keys/values
    By: Mortifis to All on Wed Apr 08 2020 01:42 am

    How would one show all of the key/values for http_request.query?

    To print out the key/values of an object, I usually like to do this (this example assumes it's being run on the telnet terminal:

    for (var prop in http_request.query)
    console.print(prop + ": " + http_request.query[prop] + "\r\n"); console.pause();

    JSON.stringify() does seem easier though:

    console.print(lfexpand(JSON.stringify(http_request.query, null, 4)));

    digital man

    Synchronet "Real Fact" #88:
    SBBSecho v3.00 was first committed to cvs.synchro.net on Apr-11-2016.
    Norco, CA WX: 54.1°F, 68.0% humidity, 7 mph NNE wind, 0.78 inches rain/24hrs

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Wednesday, April 08, 2020 15:25:17
    Re: dump all object keys/values
    By: Digital Man to Nightfox on Wed Apr 08 2020 12:59 pm

    To print out the key/values of an object, I usually like to do this
    (this example assumes it's being run on the telnet terminal:

    for (var prop in http_request.query)
    console.print(prop + ": " + http_request.query[prop] + "\r\n");
    console.pause();

    JSON.stringify() does seem easier though:

    console.print(lfexpand(JSON.stringify(http_request.query, null, 4)));

    Interesting, I'll have to try that.

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion: digitaldistortionbbs.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Friday, April 10, 2020 13:31:54
    I suppose a generic function might look like:

    function dump_objs(obj)
    {
    Object.keys(obj).forEach(function (e) {
    writeln(e + ': ' + JSON.stringify(obj[e]) + '<br>'); // run via an xjs script for html output
    });
    }

    // and a possible call:

    dump_objs(http_request.query);

    ??

    ---
    ¡ Synchronet ¡ AlleyCat! BBS Lake Echo, NS Canada
  • From echicken@VERT/ECBBS to Mortifis on Friday, April 10, 2020 12:55:29
    Re: dump all object keys/values
    By: Mortifis to echicken on Fri Apr 10 2020 13:31:54

    function dump_objs(obj)
    {
    Object.keys(obj).forEach(function (e) {
    writeln(e + ': ' + JSON.stringify(obj[e]) + '<br>'); // run via an xjs script for html output
    });
    }

    // and a possible call:

    dump_objs(http_request.query);

    Nothing wrong with doing it that way, really. If you just want to dump an object without doing a lot of formatting, then DM's suggestion (along the lines) of:

    writeln(JSON.stringify(obj, null, 4));

    is sufficient. When doing quick debugging, this is often the way I go.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    ■ Synchronet ■ electronic chicken bbs - bbs.electronicchicken.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Friday, April 10, 2020 17:18:55
    Both have their merits so I utilize them both ... thank you both!

    ~Mortifis

    ---
    ¡ Synchronet ¡ AlleyCat! BBS Lake Echo, NS Canada