Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Highlighted
Stan
New Contributor

Parsing a JSON field

I have a Qlik connection with a PostgreSQL database. I have a table called 'archive' storing a Date, a platform name and a JSON with the following structure

[
    {
        "date": "2019-04-04",
        "agency": "aaa",
        "revenue": 55
    },
    {
        "date": "2019-04-04",
        "agency": "bbb",
        "revenue": 45
    },
    {
        "date": "2019-04-03",
        "agency": "aaa",
        "revenue": 52
    },
    {
        "date": "2019-04-03",
        "agency": "bbb",
        "revenue": 42
    }
]

I am trying to have each one of these records as a row with this structure :

id, date, platform, record_date*, agency*, revenue* with the *fields coming from the Json. 

I tried messing around with the load editor but I can not figure out how to do so, is there any function allowing me to parse this JSON field ? Should I change the structure of those JSON to make this possible ?

Thanks and have a good day.

Labels (3)
1 Reply
fosuzuki
Valued Contributor II

Re: Parsing a JSON field

There is a script function to parse a JSON field. Here is an example:

Table:
load '[
    {
        "date": "2019-04-04",
        "agency": "aaa",
        "revenue": 55
    },
    {
        "date": "2019-04-04",
        "agency": "bbb",
        "revenue": 45
    },
    {
        "date": "2019-04-03",
        "agency": "aaa",
        "revenue": 52
    },
    {
        "date": "2019-04-03",
        "agency": "bbb",
        "revenue": 42
    }
]' as JSON
AutoGenerate (1);

load *
FROM_FIELD
(Table, JSON)
(json, utf8, no labels);

drop table Table;

Hope this helps.