Managing JSON Metadata
When the server accesses a data source, it needs to know how to interpret the data that it finds. For each data source the server will access, you create a synonym that describes the structure of the data source and the server mapping of the JSON data types.
Creating Synonyms
Synonyms define unique names (or aliases) for each JSON data structure that is accessible from a server. Synonyms are useful because they hide the location and identity of the underlying data source from client applications. They also provide support for extended metadata features of the server such as virtual fields and additional security mechanisms.
Using synonyms allows an object to be moved or renamed while enabling client applications to continue functioning without modification. The only modification required is a redefinition of the synonym on the server. The result of creating a synonym is a Master File and Access File based on a given JSON document.
Create a Synonym
- Procedure
- From the WebFOCUS Reporting Server browser interface Application page, click Get Data.
- On the
Configured Adapters section of the page, in Simple Mode, right-click an adapter
and click
Show
Connections. Right-click a connection.
Depending on the type of adapter you choose, one of the following options appears on the context menu.
- Show DBMS objects. This option opens the page for selecting synonym objects and properties.
- Create metadata objects. This option opens the page for selecting synonym objects and properties.
- Show files. This option opens a file picker. After you choose a file of the correct type, the page for selecting synonym objects and properties opens.
- Show local files. This option opens a file picker. After you choose a file of the correct type, the page for selecting synonym objects and properties opens.
- Show topics. This option opens the page for selecting synonym objects and properties for topics within the environment.
- Enter values for the parameters required by the adapter as described in the chapter for your adapter.
- After
entering the parameter values, click
Add.
This button may be labeled Next, Create Synonym, Create Base Synonyms, Create Cluster Synonym, or Update Base Synonyms.
The synonym creation process for most adapters has been consolidated so that you can enter all necessary parameters on one page. However, for some adapters such as LDAP, continue clicking Next until you get to a page that has a Create Synonym button.
The synonym is created and added under the specified application directory.
Synonym Creation Parameters for JSON
The following list describes the parameters for which you will need to supply values, and related tasks you will need to complete in order to create a synonym for the adapter. These options may appear on multiple panes. To advance from pane to pane, click the buttons provided, ending with the Create Synonym button, which generates the synonym based on your entries.
You can create a synonym based on a JSON document:
- Select a document instance (Step 1) and click Create Synonym based on Document Instance.
Select Document Instance parameters (Step 1 of 2)
Enables you to select a document instance from a URL. This selection requires a Base Location, Document Name, and Document Extension.
Defines the location of the document instance.
- If Use HTTP URL is not selected, enter a physical path or application directory and the JSON document name, or click the ellipsis (...) to navigate to the document.
- If Use HTTP URL is selected, enter the http address of a directory that contains the JSON document you are using to create the synonym. (This functionality is not available when the JSON document is a local file.) The URL must start with http:// or https://.
Enter the name of the JSON document.
Enter the document extension. The default is JSON.
Clicking this button enables you to create the synonym from the document instance.
Create Synonym for JSON (Step 2 of 2)
Select the Validate checkbox if you wish to convert all special characters to underscores and perform a name check to prevent the use of reserved names. (This is accomplished by adding numbers to the names.) This parameter ensures that names adhere to specifications. See Validation for Special Characters and Reserved Words for more information.
When the Validate option is unchecked, only the following characters are converted to underscores: '-'; ' '; ' \'; '/'; ','; '$'. No checking is performed for names.
Select the Make unique checkbox if you wish to set the scope for field and group names to the entire synonym. This ensures that no duplicate names are used, even in different segments of the synonym. When this option is unchecked, the scope is the segment.
Indicates the name that will be assigned to the synonym. To assign a different name, replace the displayed value.
Select an application directory. The default value is baseapp.
If you have tables with identical table names, assign a prefix or a suffix to distinguish them. For example, if you have identically named human resources and payroll tables, assign the prefix HR to distinguish the synonyms for the human resources tables. Note that the resulting synonym name cannot exceed 64 characters.
If all tables and views have unique names, leave the prefix and suffix fields blank.
To specify that this synonym should overwrite any earlier synonym with the same fully qualified name, select the Overwrite existing synonyms checkbox.
Managing Synonyms
Once you have created a synonym, you can right-click the synonym name in the navigation pane of either the WebFOCUS Reporting Server browser interface or ibi Data Migrator desktop interface to access the available options.
For a list of options, see Synonym Management Options.
Accessing JSON Documents From a Relational DBMS JSON Data Type
JSON documents might be stored in any fields or columns in any data source. Reporting from such documents is supported by defining their structure as subtrees attached to a parent segment which describes the original data.
The synonym creation process must be run against the data in the DBMS and against the JSON document. The two Master Files must then be combined to make the JSON Master File a child of the Master File created against the DBMS. A FILEDEF is not needed in this instance.
Access JSON Data From an RDBMS Using ibi WebFOCUS Reporting Server browser interface or ibi Data Migrator desktop interface Tools
- Procedure
- Using the WebFOCUS Reporting Server browser interface or ibi Data Migrator desktop interface Create Synonym facility, generate a synonym for an RDBMS data source that contains a column of JSON data. Regardless of the data type used to contain the JSON data in the native data source, it will be mapped as a TX column in the Master File synonym. (For many RDBMS engines, the CLOB data type is mapped to TX.)
- Open the generated Master File in the Synonym Editor.
The Master File appears in the right pane in Text View. For example,
the Master File for a Db2 data source might look as follows:
FILENAME=TESTJSON, SUFFIX=DB2 , $ SEGMENT=TESTJSON, SEGTYPE=S0, $ FIELDNAME=STORE, ALIAS=STORE, USAGE=A30, ACTUAL=A30, $ FIELDNAME=ADDRESS, ALIAS=ADDRESS, USAGE=A20, ACTUAL=A20, MISSING=ON, $ FIELDNAME=GLOSS, ALIAS=GLOSS, USAGE=TX50, ACTUAL=TX, MISSING=ON, $
- From ibi Data Migrator desktop interface, right-click a column described as TX that contains JSON data. The pop-up menu contains the Pivot option.
- Select Pivot, then Multiple values to rows.
This option reads the JSON column directly and creates a new segment with SEGSUF=JSON.
The Select mapping source dialog opens.
- Select Rows to sample for structural analysis and click Next.
The Column mapping dialog opens displaying two rows from the column that is being pivoted.
Examine the data to make sure it looks like JSON.
- In the Select data type pull-down list, select JSON and click Apply.
The resulting Master File contains the definition of the JSON data, represented as a new DUMROOT segment with SEGSUF=JSON, which appears in the Text View pane following the original RDBMS segment.
You can expand DUMROOT to see the names of the fields found in the JSON.
You can right-click DUMROOT to see the values of those fields.
The Master File might now look as follows, with the DUMROOT segment containing the data from the JSON column:
FILENAME=testjson, SUFFIX=DB2 , $ SEGMENT=TESTJSON, SEGTYPE=S0, $ FIELDNAME=STORE, ALIAS=STORE, USAGE=A30, ACTUAL=A30, $ FIELDNAME=ADDRESS, ALIAS=ADDRESS, USAGE=A20, ACTUAL=A20, MISSING=ON, $ FIELDNAME=GLOSS, ALIAS=GLOSS, USAGE=TX50, ACTUAL=TX, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $ SEGMENT=DUMROOT, SEGTYPE=S0, SEGSUF=JSON , PARENT=TESTJSON, POSITION=GLOSS, $ FIELDNAME=DUMROOT, ALIAS=JSON_DUMMY_EL, USAGE=A1, ACTUAL=A1, ACCESS_PROPERTY=(INTERNAL), $ FIELDNAME=TITLE, ALIAS=title, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSARY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSDIV, ALIAS=GlossDiv, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSARY, PROPERTY=ELEMENT, $ FIELDNAME=TITLE1, ALIAS=title, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDIV, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSLIST, ALIAS=GlossList, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSDIV, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSENTRY, ALIAS=GlossEntry, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSLIST, PROPERTY=ELEMENT, $ FIELDNAME=ID, ALIAS=ID, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=SORTAS, ALIAS=SortAs, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSTERM, ALIAS=GlossTerm, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $
FIELDNAME=ACRONYM, ALIAS=Acronym, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=ABBREV, ALIAS=Abbrev, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSDEF, ALIAS=GlossDef, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=PARA, ALIAS=para, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDEF, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSSEE, ALIAS=GlossSee, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ SEGMENT=GLOSSSEEALSO, SEGTYPE=S0, PARENT=GLOSSARY, $ FIELDNAME=GLOSSSEEALSO, ALIAS=GlossSeeAlso, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDEF, PROPERTY=ELEMENT, $
- Select Rows to sample for structural analysis and click Next.
- From the Synonym Editor's File menu, save the updated Master File.
Access JSON Data From an RDBMS Manually
Suppose that you have a table in an RDBMS with one or more columns storing JSON data. In order to report from the JSON data, following these steps:
- Procedure
- Create the Master File for the relational data
source using the format for that DBMS.
FILENAME=TESTJSON, SUFFIX=DB2 , $ SEGMENT=TESTJSON, SEGTYPE=S0, $ FIELDNAME=STORE, ALIAS=STORE, USAGE=A30, ACTUAL=A30, $ FIELDNAME=ADDRESS, ALIAS=ADDRESS, USAGE=A20, ACTUAL=A20, MISSING=ON, $ FIELDNAME=GLOSS, ALIAS=GLOSS, USAGE=TX50, ACTUAL=TX, MISSING=ON, $
- Create a Master File for the JSON document in the column of the RDBMS table. If there are two JSON documents with different formats, you must create a Master File for each one.
- Manually combine the Master Files. On each root segment
for the JSON Master File, add three fields: position, parent, and
segsuf. The POSITION keyword identifies the field containing the
JSON document. The PARENT field describes the original data source.
The field SEGSUF defines the root segment of a JSON document representing
sub-tree. The total length of all fields in the Master File must
not exceed the FOCUS limitation of 32k. If it does, the query will
fail.
FILENAME=BASEAPP_GLOSSARY, SUFFIX=JSON , DATASET=c:\json\glossary.json, $ SEGMENT=GLOSSARY, SEGTYPE=S0, $ FIELDNAME=GLOSSARY, ALIAS=glossary, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $ FIELDNAME=TITLE, ALIAS=title, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSARY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSDIV, ALIAS=GlossDiv, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSARY, PROPERTY=ELEMENT, $ FIELDNAME=TITLE1, ALIAS=title, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDIV, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSLIST, ALIAS=GlossList, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSDIV, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSENTRY, ALIAS=GlossEntry, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSLIST, PROPERTY=ELEMENT, $ FIELDNAME=ID, ALIAS=ID, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=SORTAS, ALIAS=SortAs, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSTERM, ALIAS=GlossTerm, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=ACRONYM, ALIAS=Acronym, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $
FIELDNAME=ABBREV, ALIAS=Abbrev, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSDEF, ALIAS=GlossDef, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=PARA, ALIAS=para, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDEF, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSSEE, ALIAS=GlossSee, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ SEGMENT=GLOSSSEEALSO, SEGTYPE=S0, PARENT=GLOSSARY, $ FIELDNAME=GLOSSSEEALSO, ALIAS=GlossSeeAlso, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDEF, PROPERTY=ELEMENT, $
Combined Master file:
FILENAME=testjson, SUFFIX=DB2 , $ SEGMENT=TESTJSON, SEGTYPE=S0, $ FIELDNAME=STORE, ALIAS=STORE, USAGE=A30, ACTUAL=A30, $ FIELDNAME=ADDRESS, ALIAS=ADDRESS, USAGE=A20, ACTUAL=A20, MISSING=ON, $ FIELDNAME=GLOSS, ALIAS=GLOSS, USAGE=TX50, ACTUAL=TX, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $ SEGMENT=GLOSSARY, SEGTYPE=S0, SEGSUF=JSON , PARENT=TESTJSON, POSITION=GLOSS, $ FIELDNAME=GLOSSARY, ALIAS=glossary, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), $ FIELDNAME=TITLE, ALIAS=title, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSARY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSDIV, ALIAS=GlossDiv, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSARY, PROPERTY=ELEMENT, $ FIELDNAME=TITLE1, ALIAS=title, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDIV, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSLIST, ALIAS=GlossList, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSDIV, PROPERTY=ELEMENT, $
FIELDNAME=GLOSSENTRY, ALIAS=GlossEntry, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSLIST, PROPERTY=ELEMENT, $ FIELDNAME=ID, ALIAS=ID, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=SORTAS, ALIAS=SortAs, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSTERM, ALIAS=GlossTerm, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=ACRONYM, ALIAS=Acronym, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=ABBREV, ALIAS=Abbrev, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSDEF, ALIAS=GlossDef, USAGE=A1, ACTUAL=A1, MISSING=ON, ACCESS_PROPERTY=(INTERNAL), REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $
FIELDNAME=PARA, ALIAS=para, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDEF, PROPERTY=ELEMENT, $ FIELDNAME=GLOSSSEE, ALIAS=GlossSee, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSENTRY, PROPERTY=ELEMENT, $ SEGMENT=GLOSSSEEALSO, SEGTYPE=S0, PARENT=GLOSSARY, $ FIELDNAME=GLOSSSEEALSO, ALIAS=GlossSeeAlso, USAGE=A55, ACTUAL=A55, MISSING=ON, REFERENCE=GLOSSDEF, PROPERTY=ELEMENT, $
Conversion
The data in a JSON document may reflect dates or numeric values, however, all the fields in a Master File synonym are set to the ALPHA data type.
Numeric Values
In order to enable arithmetic operations on numeric fields, the data type specified in the USAGE attribute of a numeric field needs to be modified, depending on the data in the JSON document, to one of the following data types: Integer (I), Double Float (D), or Decimal (P). If the data type is modified to Double Float or Decimal, use scale and precision as necessary to describe the data in the JSON document.
Furthermore, it is recommended that the length of the ALPHA data type specified in the ACTUAL attribute of the numeric field be modified to reflect the maximum length of the data in the JSON document.
Dates in JSON
In order to enable arithmetic operations on dates, the data type specified in the USAGE attribute of a date field needs to be modified, depending on the date format used in the JSON document, to one of the following data types: YYMD, MDYY, or DMYY.
Furthermore, the length of the ALPHA data type specified in the ACTUAL attribute of the date field needs to be modified to 10.
- Once you have set the data type in the Master File to one of the date data types, you must make sure that in each of the JSON documents from which you report the date format is the same as the one you defined in the Master File. If the data types differ, an error will result.
- The date format in the answer set is not derived from the date format used in the JSON document and is always set to YYYY/MM/DD.
Using Dates in JSON
If in the JSON document you have the following format: |
Then use USAGE= |
---|---|
1996-01-30 |
YYMD |
01-30-1996 |
MDYY |
30-01-1996 |
DMYY |