Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED]JSON data within a master file

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED]JSON data within a master file
 Login/Join
 
Silver Member
posted
I have an oracle db that has a field which contains JSON data that I need to parse into individual fields in my synonym.

The structure is [{"Server":"abc","Owner":"def","Description":"xyz","RowID":"12345"}]

The segment in my master file looks like this...

FIELDNAME=STORESERVERJSON, ALIAS=STORESERVERJSON, USAGE=TX50, ACTUAL=TX,
MISSING=ON,
TITLE='Server JSON', $
SEGMENT=SERVER, SEGTYPE=S0, SEGSUF=JSON, PARENT=DB_SERVER_VIEW, POSITION=STORESERVERJSON, $
FIELDNAME=Server, ALIAS=Server, USAGE=A400V, ACTUAL=A400V,
REFERENCE=Server, PROPERTY=ELEMENT, $
FIELDNAME=Owner, ALIAS=Owner, USAGE=A400V, ACTUAL=A400V,
REFERENCE=Server, PROPERTY=ELEMENT, $
FIELDNAME=Description, ALIAS=Description, USAGE=A400V, ACTUAL=A400V,
REFERENCE=Server, PROPERTY=ELEMENT, $
FIELDNAME=RowID, ALIAS=RowID, USAGE=A400V, ACTUAL=A400V,
REFERENCE=Server, PROPERTY=ELEMENT, $

I don't have error but I'm not getting any data in the fields in my JSON segment (I get data in the top level segment). What am I missing?

This message has been edited. Last edited by: <Emily McAllister>,


WebFOCUS 8.0.09
Windows, All Outputs
 
Posts: 36 | Registered: November 19, 2014Report This Post
Expert
posted Hide Post
I don't like your chances, as its a relation DB and the segment you are creating doesn't know the format of the json.

I'm not even sure that you can create a segment of a TX field.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
I would try to approach this relational.

My first idea is to create a separate master for just the JSON data, with each JSON attribute as a field and relating it to the 'main' master (for lack of a better name) by the RowID field. It's easy to create a master file on a JSON format for reference using the CAR table:
APP HOLD BASEAPP

TABLE FILE CAR
PRINT
	BODYTYPE

BY COUNTRY
BY CAR
ON TABLE HOLD AS CARJSON FORMAT JSON
END


Alternatively, you could create a database view on that JSON section, provided that Oracle has features to interpret JSON (I know of another RDBMS that it does).

That's under the assumption that your JSON data is of a fixed format, with the above fields: "Server", "Owner", "Description" and "RowID".

If not, I think your chances of describing that JSON data with a master in any way are rather slim.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Virtuoso
posted Hide Post
You don't have an absolute parent. I copied you JSON to a file and when I created the MFD it added a dummy field. You might want to try that. BTW, I have done what you are trying to do, so it should work.

SEGMENT=JSON_DUMMY_EL, SEGTYPE=S0, SEGSUF .......
    FIELDNAME=JSON_DUMMY_EL, ALIAS=JSON_DUMMY_EL, USAGE=A1, ACTUAL=A1,
      MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $
    FIELDNAME=SERVER, ALIAS=Server, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=OWNER, ALIAS=Owner, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=DESCRIPTION, ALIAS=Description, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=ROWID, ALIAS=RowID, USAGE=P33, ACTUAL=A33,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $  


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
 
Posts: 1102 | Location: Toronto, Ontario | Registered: May 26, 2004Report This Post
Master
posted Hide Post
quote:
Originally posted by Wep5622:
It's easy to create a master file on a JSON format for reference using the CAR table:
APP HOLD BASEAPP

TABLE FILE CAR
PRINT
	BODYTYPE

BY COUNTRY
BY CAR
ON TABLE HOLD AS CARJSON FORMAT JSON
END


I'll be darned. I didn't realize JSON was a format option for a HOLD file.

Here's code that extracts the JSON data from your HOLD file example:

APP HOLD BASEAPP

TABLE FILE CAR
PRINT
	BODYTYPE

BY COUNTRY
BY CAR
ON TABLE HOLD AS CARJSON FORMAT JSON
END

-HTMLFORM BEGIN
<script type="text/javascript">
function build_table() {
	var recs = !IBI.FIL.CARJSON;

	var body = document.getElementById("carjson");
	var table = document.createElement("table");
	var tableBody = document.createElement("tbody");

	for (var i = 0; i < recs.records.length; i++) {
		var tableRow = document.createElement("tr");

		var cell = document.createElement("td");
		var cellText = document.createTextNode(recs.records[i].COUNTRY);
		cell.appendChild(cellText);
		tableRow.appendChild(cell);

		var cell = document.createElement("td");
		var cellText = document.createTextNode(recs.records[i].CAR);
		cell.appendChild(cellText);
		tableRow.appendChild(cell);

		var cell = document.createElement("td");
		var cellText = document.createTextNode(recs.records[i].BODYTYPE);
		cell.appendChild(cellText);
		tableRow.appendChild(cell);

		tableBody.appendChild(tableRow);
	}

	table.appendChild(tableBody);
	body.appendChild(table);
        table.setAttribute("border", "1");
        table.setAttribute("cellpadding", "6");
}
</script>
<body id="carjson" onload="build_table()">

</body>
-HTMLFORM END


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Report This Post
Silver Member
posted Hide Post
quote:
Originally posted by dhagen:
You don't have an absolute parent. I copied you JSON to a file and when I created the MFD it added a dummy field. You might want to try that. BTW, I have done what you are trying to do, so it should work.

SEGMENT=JSON_DUMMY_EL, SEGTYPE=S0, SEGSUF .......
    FIELDNAME=JSON_DUMMY_EL, ALIAS=JSON_DUMMY_EL, USAGE=A1, ACTUAL=A1,
      MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $
    FIELDNAME=SERVER, ALIAS=Server, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=OWNER, ALIAS=Owner, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=DESCRIPTION, ALIAS=Description, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=ROWID, ALIAS=RowID, USAGE=P33, ACTUAL=A33,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $  


I added the absolute parent, but I'm still not getting any data returned. It's almost like it's missing the connection between the field containing the JSON and the JSON segment.


Is there any reliable documentation on how to set this up? The examples in the technical library aren't real clear.


WebFOCUS 8.0.09
Windows, All Outputs
 
Posts: 36 | Registered: November 19, 2014Report This Post
Virtuoso
posted Hide Post
quote:
Originally posted by MelissaReed:
Is there any reliable documentation on how to set this up? The examples in the technical library aren't real clear.


I haven't seen any. I've done a lot with SEGSUF, but it's all been trial and error up to this point. I'll see if I can put a full example together, but I might not have the time until next week.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
 
Posts: 1102 | Location: Toronto, Ontario | Registered: May 26, 2004Report This Post
Silver Member
posted Hide Post
quote:
Originally posted by dhagen:
quote:
Originally posted by MelissaReed:
Is there any reliable documentation on how to set this up? The examples in the technical library aren't real clear.


I haven't seen any. I've done a lot with SEGSUF, but it's all been trial and error up to this point. I'll see if I can put a full example together, but I might not have the time until next week.


Thank you, I would really appreciate it!


WebFOCUS 8.0.09
Windows, All Outputs
 
Posts: 36 | Registered: November 19, 2014Report This Post
Virtuoso
posted Hide Post
I don't have Oracle handy at the moment, so I did this in SQL Server.
- I created a table with 2 columns, VARCHAR and a VARCHAR(MAX)
Looks like:
HASH	                                JSON_OBJECT
00d16a47b729398e2caa1042dec33936	[{"Server":"abc","Owner":"def","Description":"xyz","RowID":"00d16a47b729398e2caa1042dec33936"}]
0220e3e48aa78dd332d4d279d7d6df4a	[{"Server":"abc","Owner":"def","Description":"xyz","RowID":"0220e3e48aa78dd332d4d279d7d6df4a"}]
044bda4b0b7e22781ec11c402f6277d2	[{"Server":"abc","Owner":"def","Description":"xyz","RowID":"044bda4b0b7e22781ec11c402f6277d2"}]
0a3bab0ba05933a93c1b8f0cd3c81d6b	[{"Server":"abc","Owner":"def","Description":"xyz","RowID":"0a3bab0ba05933a93c1b8f0cd3c81d6b"}]  


I created the MFD then altered it to:
FILENAME=JSON_TEST_FILE_WITH_JSON, SUFFIX=SQLMSS  , $
  SEGMENT=JSON_TEST_FILE_WITH_JSON, SEGTYPE=S0, $
    FIELDNAME=HASH, ALIAS=HASH, USAGE=A32V, ACTUAL=A32V, $
    FIELDNAME=JSON_OBJECT, ALIAS=JSON_OBJECT, USAGE=TX50, ACTUAL=TX, ACCESS_PROPERTY=(INTERNAL), $
  SEGMENT=JSON_DUMMY_EL, SEGTYPE=S0, SEGSUF=JSON, POSITION=JSON_OBJECT, 
    FIELDNAME=JSON_DUMMY_EL, ALIAS=JSON_DUMMY_EL, USAGE=A1, ACTUAL=A1,
      MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $
    FIELDNAME=SERVER, ALIAS=Server, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=OWNER, ALIAS=Owner, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=DESCRIPTION, ALIAS=Description, USAGE=A55, ACTUAL=A55,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $
    FIELDNAME=ROWID, ALIAS=RowID, USAGE=A32, ACTUAL=A32,
      MISSING=ON,
      REFERENCE=JSON_DUMMY_EL, PROPERTY=ELEMENT,  $    


It reports fine with all values being displayed properly.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
 
Posts: 1102 | Location: Toronto, Ontario | Registered: May 26, 2004Report This Post
Silver Member
posted Hide Post
Thank you for the detailed example. The problem with my need is that all of my JSON data is actually stored within a column in my table. I don't have a link like HASH to connect the two. I need it to be able to read that field and create the fields based on the structure.


WebFOCUS 8.0.09
Windows, All Outputs
 
Posts: 36 | Registered: November 19, 2014Report This Post
Expert
posted Hide Post
quote:
I'll be darned. I didn't realize JSON was a format option for a HOLD file.


Warning.

In 8.1.04, using HOLD FORMAT JSON with 1 record adds an extra { to the output.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Master
posted Hide Post
quote:
Originally posted by Waz:
quote:
I'll be darned. I didn't realize JSON was a format option for a HOLD file.


Warning.

In 8.1.04, using HOLD FORMAT JSON with 1 record adds an extra { to the output.

Thanks for the warning. Good thing I'm on 8.1.05:

{
  "records" : [
      { "CAR" : "JAGUAR" }
  ]
}


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Report This Post
Expert
posted Hide Post
Good to know its fixed in 8.1.05


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
quote:
Originally posted by MelissaReed:
Thank you for the detailed example. The problem with my need is that all of my JSON data is actually stored within a column in my table. I don't have a link like HASH to connect the two. I need it to be able to read that field and create the fields based on the structure.


The HASH is irrelevant to the example, it is only there because I've been working on a MD5 FUSE subroutine and was testing my work and your example at the same time. Remove the HASH column from the table and MFD and it and the example still works fine.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
 
Posts: 1102 | Location: Toronto, Ontario | Registered: May 26, 2004Report This Post
Platinum Member
posted Hide Post
MelissaReed -

Likely this is not the answer you were looking for, but I'm curious as to why you are trying to use this particular Oracle column for your report.

json format is useful for certain types of reports and data movement, but this is not what you are doing.

Rather than trying to somehow "unpack" this column - which has 4 data fields - perhaps you can go back to the original data source(s) that took those 4 data fields and squished them into this Oracle column?
 
Posts: 164 | Registered: March 26, 2003Report This Post
Silver Member
posted Hide Post
dhagen - What version of WF and which DB and version are you using where you have been able to get the JSON to work?


WebFOCUS 8.0.09
Windows, All Outputs
 
Posts: 36 | Registered: November 19, 2014Report This Post
Virtuoso
posted Hide Post
8.1.04 and SQL Server 2012.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
 
Posts: 1102 | Location: Toronto, Ontario | Registered: May 26, 2004Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED]JSON data within a master file

Copyright © 1996-2020 Information Builders