Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

CA and Jupyter Notebook Server 11.2.4: Upload json data not possible ?

  • 1.  CA and Jupyter Notebook Server 11.2.4: Upload json data not possible ?

    Posted Tue December 05, 2023 08:28 AM
      |   view attached

    How can json or other 'non supported' data types be made available for analysis in notebooks ?



    ------------------------------
    Thomas Strehl
    ------------------------------


  • 2.  RE: CA and Jupyter Notebook Server 11.2.4: Upload json data not possible ?

    Posted Wed December 06, 2023 11:32 AM
    Edited by Andres Parada Thu December 07, 2023 04:09 PM

    Hi Thomas,

    Are you trying to upload the data file(s) to the Cognos content store? Yes, you are correct, CA will not allow you to upload arbitrary file types in the CA content store ( it only lets you upload files of the types used by CA. The data upload UI, for example, allows you to upload excel files, csv files, jupyter notebook files, or  zip files of these.) 

    If you want to work with data files in different formats (e.g. JSON) in IBM Cognos Analytics for Jupyter Notebook, you will need to look at a different content management strategy for these files. The most straight-forward is to put these files somewhere that will serve them up and be accessible to your notebook code, like a web server/FTP server or a network share. If you want to put them somewhere where you can control user access, you could also look at storing them in something like Box, Dropbox, IBM Cloud Object Storage (COS) or Github (or even a database), then using the respective Python packages to access them in your notebook. As an example, here's a Python snippet I use to read a file I have in Github (note: "sensitive" token text in my call "XXX"ed out ;-) ):

    import pandas as pd
    import json
    from github import Github
    from github import Auth

    # authenticate with Github - note: need to create a token in github for this

    auth = Auth.Token("XXX")
    g = Github(auth=auth)
    repo = g.get_repo("autocoreinsightz/data")

    #get reference to the file in Github

    contents = repo.get_contents("hockey/injuries.json")

    #read JSON file data in from Github repo

    rawtext = contents.decoded_content.decode()

    jsondata = json.loads(rawtext)

    #Update file in Github

    rawtext = json.dumps(jsondata, indent = 4)
    repo.update_file(contents.path, "automated update to curated data file", rawtext, contents.sha, branch="main")

    https://pygithub.readthedocs.io/en/stable/introduction.html

    Of course, once you've pulled the data into your notebook, you can use the CADataConnector class (in IBM Cognos Analytics for Jupyter Notebook) to write the data back into CA as a data source, to be used in Reports, Dashboards, or even other Notebooks. 



    ------------------------------
    Jim Boland

    LinkedIn: https://www.linkedin.com/in/jimboland
    Website: https://coreinsightz.com
    Email: jimboland@coreinsightz.com
    ------------------------------