displaying json data

displaying json data

tyrrvktyrrvk Posts: 6Questions: 1Answers: 0

Hi -
I'm trying to take json formatted output from a program, and use datatables to display it.
The program that generates the output is LMOD. You can see a couple examples of the type of json outputted here:
https://lmod.readthedocs.io/en/latest/136_spider.html

How do I ingest (is that the right term) this file into something datatables can parse?
I'm looking at using the AJAX columns stuff, but the json I'm bringing in, isn't as simple as the keypair examples provided...There's a lot of nested stuff, and what appears to be headers which are singular entries (not a pair).

I'm confused on a couple of things. For one, I am not passing an array to datatables, but rather an AJAX object correct?
Do I define the .json file here:
"ajax": "data/objects.txt",
but with it being "ajax": "http://blah.blah/myfile.json"

Any help is appreciated.

This question has accepted answers - jump to:

Answers

  • tyrrvktyrrvk Posts: 6Questions: 1Answers: 0

    So I got this working - for the most part, but I am getting one error:
    DataTables warning: table id=example - Requested unknown parameter 'defaultVersionName' for row 1, column

    The code is:

    <

    script>
    $(document).ready(function() {
    $('#example').DataTable( {
    "ajax": {
    "url": "software.json",
    "dataSrc": ""
    },
    "columns": [
    { "data": "defaultVersionName" },
    { "data": "package" },
    { "data": "description" }
    ]
    } );
    } );

    I did notice in my software.json file, that defaultVersionName is missing on some of the entries. Is there a way to ignore the few cases this field is missing?

  • kthorngrenkthorngren Posts: 20,649Questions: 26Answers: 4,836
    Answer ✓

    I think you can use columns.defaultContent for this. See the second example in the docs.

    Kevin

  • tyrrvktyrrvk Posts: 6Questions: 1Answers: 0
    edited February 2019

    Thank you - that did it.

    One last issue. I am trying to pull in nested data from my json file, using the dotted notation,
    {
    "data": "versions.full",
    "defaultContent": ""
    },

    but it's coming up blank. Looking at the json file I see:

       "versions": [
            {
                "canonicalVersionString": "000002017.*_.*update.000000004.*zfinal",
                "full": "Mentor-AFS/2017_update4",
                "help": "For help with AFS, plus refer to the support portal located at: https://support.mentor.com/en/\n",
                "markedDefault": false,
                "path": "/etc/modulefiles/software/Mentor-AFS/2017_update4.lua",
                "versionName": "2017 Update 4",
                "wV": "000002017.*_.*update.000000004.*zfinal"
            },
            {
                "canonicalVersionString": "000002017.*update.000000004.*zfinal",
                "full": "Mentor-AFS/2017-update4",
    

    But when I look at it in the browser, I get an array index, 0,1 etc. Do I need to include that index in the dotted notation? The versions range varies in most cases.

    thanks.

  • colincolin Posts: 15,209Questions: 1Answers: 2,592
    Answer ✓

    Hi @tyrrvk ,

    I think this example here is what you're after. You need

          data: 'versions[, ].full'
    

    Cheers,

    Colin

This discussion has been closed.