Parse CSV in JSON object

  • 3 October 2023
  • 3 replies

Userlevel 3
Badge +1


I have a JSON data source that looks something like this

"company": {
"companyId": 1,
"name": "AdventureWorks",
"description": ""
"hierarchies": [
"depths": [
"depth": 0,
"name": null
"depth": 1,
"name": "Company"
"allKeys": "1|-1|10"
"slicer": null,
"userToGroup": "Username,GroupId\nJohn,G1\nSarah,G1\nPeter,G1\nKate,G1",
"groupToKey": "GroupId,Key\nG1,10\nG1,101\nG1,102\nG1,103\nG1,104"

And I am only really interested in the last two objects, userToGroup and groupToKey, which both are in a CSV format. Is it possible to use something like xPath to navigate to these two objects and then parse them as CSVs? 

I have an RSD file that gives me userToGroup:

<api:script xmlns:api="" xmlns:xs="">

<!-- See Column Definitions to specify column behavior and use XPaths to extract column values from JSON. -->
<api:info title="hierarchies" desc="Generated schema file." xmlns:other="">
<!-- You can modify the name, type, and column size here. -->
<attr name="json.userToGroup" xs:type="string" readonly="false" other:xPath="/json/userToGroup" />

<api:set attr="DataModel" value="DOCUMENT" />
<api:set attr="URI" value="" />

<api:set attr="JSONPath" value="$.hierarchies" />

But everything ends up in a single column/row. 

Does anyone have any experience working with this sort of JSON/CSV format combination?


Best answer by Thomas Lind 4 October 2023, 15:32

View original

3 replies

Userlevel 6
Badge +5

Hi Pontus

To make a RSD file that can both use CSV and JSON in one will be rather difficult.

I would instead suggest to do something similar to what I do in this project.

I have all the data in one field, so both names and content.

So this

Becomes this


Userlevel 6
Badge +7


you should be able to split the strings using String formatter expressions (see: as long as the strings have a somewhat predictable structure. It might also be possible to use the regex string formatters to convert the mini-csv into a json array and have the connector deal with pulling that apart. 

Whether or not you find .rsd magic easier / better than doing the string splitting in SQL is a matter of taste, though I don't like hiding logic in .rsd much.

Userlevel 3
Badge +1


Thanks for the advice. I took inspiration from Thomas’ project and did the string splitting in SQL. It is indeed more visible to have the logic in scripts in TimeXtender, rather than hidden away in .rsd files.