Making blocks optional and conditional entry where there is no header name - json

I am trying to write a json schema to import a csv file. A simplified version of the file is:
000,OUTCOME,111,20220320,FT
001,A.Name1,,,A,
002,A.Name2,,20220101,C,
999,2
000 is a header block
001 & 002 are the body and can have multiple instances. Structurally they are the same
999 is the trailer
the schema I have is
{
"conf_name": "FileTest",
"has_blocks": true,
"has_headers": false,
"enabled_extensions": [
{
"extension": "csv",
"delimiter": ","
}
],
"file_type": "FileTest",
"columns": [
{
"blockName": "000",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "text",
"format": "",
"values": [
"OUTCOME"
],
"conditional": ""
}
},
{
"blockName": "000",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "int",
"format": "",
"values": "",
"conditional": ""
}
},
{
"blockName": "000",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "date",
"format": "yyyyMMdd",
"values": "",
"conditional": ""
}
},
{
"blockName": "000",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "text",
"format": "",
"values": "",
"conditional": ""
}
},
{
"blockName": "001",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "text",
"format": "",
"values": "",
"conditional": ""
}
},
{
"blockName": "001",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "O",
"type": "text",
"format": "",
"values": "",
"conditional": ""
}
},
{
"blockName": "001",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "C",
"type": "date",
"format": "yyyyMMdd",
"values": "",
"conditional": {
"columnName": "Column5",
"operation": "==C THEN NOTEMPTY",
"value": ""
}
}
},
{
"blockName": "001",
"name": "Column5",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "text",
"format": "",
"values": [
"A",
"B",
"C"
],
"conditional": ""
}
},
{
"blockName": "001",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "O",
"type": "text",
"format": "",
"values": [
"Y",
"N"
],
"conditional": ""
}
},
{
"blockName": "002",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "text",
"format": "",
"values": "",
"conditional": ""
}
},
{
"blockName": "002",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "O",
"type": "text",
"format": "",
"values": "",
"conditional": ""
}
},
{
"blockName": "002",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "C",
"type": "date",
"format": "yyyyMMdd",
"values": "",
"conditional": {
"columnName": "Column5",
"operation": "==C THEN NOTEMPTY",
"value": ""
}
}
},
{
"blockName": "002",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "text",
"format": "",
"values": [
"A",
"B",
"C"
],
"conditional": ""
}
},
{
"blockName": "002",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "O",
"type": "text",
"format": "",
"values": [
"Y",
"N"
],
"conditional": ""
}
},
{
"blockName": "999",
"name": "",
"startPosition": "",
"maxLength": "",
"minLength": "",
"data": {
"mandatory": "M",
"type": "int",
"format": "",
"values": "",
"conditional": ""
}
}
]
}
I apologise now if that is an affront to JSON users everywhere!
This works if there are both 001 and 002 lines in the file, but I've now been told that there may times when the file is all 001 or 002 but not both. Is there a way to make them optional? "oneOf" seemed likely, but I could not fathom how to use it in this situation.
My other issue was with the conditional entry. The data does not have a header row so I'm not sure how to check it. The intention is that if the 5th column contains a "C" then the 4th should have a date in it.
Any help would be gratefully received. Thanks

Related

Recursively Parsing Nested JSON with PostgreSQL

I'm trying to parse a nested JSON in Postgres, which has the following structure:
{
"id": "Hrr3yh_Bgbf3sS35cI5g1",
"title": "Test Porcedure",
"notes": "",
"revision": "",
"status": "COMPLETED",
"description": "N/A",
"create_date": "2022-09-01T15: 28: 01.144Z",
"update_date": "2022-09-01T15: 28: 01.144Z",
"items": [
{
"id": "Wd4FxS3J6O4yAwES20E27",
"type": "SECTION",
"items": [
{
"id": "cYgmal2OzkA6satAyA30M",
"type": "GROUP",
"items": [
{
"id": "tVhFnDUIOnAjW5uBagnEp",
"na": true,
"skip": false,
"type": "PASS/FAIL",
"warn": true,
"label": "",
"_group": "cYgmal2OzkA6satAyA30M",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": ""
},
{
"id": "JeUUbwcSEpSPHqSM_SmUL",
"na": true,
"skip": false,
"type": "YES/NO",
"warn": true,
"label": "",
"_group": "cYgmal2OzkA6satAyA30M",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
},
{
"id": "hsx6tdMuAnSfKXJ1FNV5_",
"na": false,
"skip": false,
"type": "TASK ITEM",
"warn": false,
"label": "",
"_group": "cYgmal2OzkA6satAyA30M",
"repeat": 1,
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": "",
"checkbox_label": "Completed"
}
],
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "6y0kWDg9T4g0DmAzlSOkj",
"type": "INSTRUCTION",
"title": "",
"content": "",
"infoPanel": "none",
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "595O0C-eEN2A0oQvZ7uuj",
"type": "GROUP",
"items": [
{
"id": "MWb-KkigeaJCHUIBMV4YX",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "595O0C-eEN2A0oQvZ7uuj",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
},
{
"id": "chY0siMNszJNcdtcFoFIJ",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "595O0C-eEN2A0oQvZ7uuj",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
},
{
"id": "t4EX6FpooalFGv0MKr6cv",
"na": false,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "595O0C-eEN2A0oQvZ7uuj",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": ""
},
{
"id": "hS-3DZJ3S5fOMo24kH5ZQ",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "595O0C-eEN2A0oQvZ7uuj",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
}
],
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "FteFQ173r1dfI310xkljO",
"url": "",
"type": "CUSTOM",
"label": "",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": "",
"configuration": ""
},
{
"id": "swgsqHl1BkJuSA9AjoS7h",
"type": "GROUP",
"items": [
{
"id": "EnEben7GwMCYM4qdGQUN6",
"na": false,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "swgsqHl1BkJuSA9AjoS7h",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": ""
}
],
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "dDpKHg2E-Vj2UjOZsGiVD",
"type": "SUB-SECTION",
"items": [
{
"id": "yVrtKVS2xrLMUsxT3jd2S",
"type": "GROUP",
"items": [
{
"id": "D5zareFNaNbqH7MqA9tM0",
"na": false,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "yVrtKVS2xrLMUsxT3jd2S",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": ""
},
{
"id": "sSBLzmxxHBK67C8-bwcwt",
"na": false,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "yVrtKVS2xrLMUsxT3jd2S",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": ""
},
{
"id": "GP9_oCLOI58cqvqWRiwAB",
"na": false,
"skip": false,
"type": "TASK ITEM",
"warn": false,
"label": "",
"_group": "yVrtKVS2xrLMUsxT3jd2S",
"repeat": 1,
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": "",
"checkbox_label": "Completed"
}
],
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "9OhCrZ5q4YKxd1iTT_gMj",
"url": "",
"type": "CUSTOM",
"label": "",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": "",
"configuration": ""
},
{
"id": "WKe1gv30O8C4aKp8ABTRh",
"type": "INSTRUCTION",
"title": "",
"content": "",
"infoPanel": "none",
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "pzQm1B7UU6QpWMDK4JATW",
"type": "GROUP",
"items": [
{
"id": "-s3GDJC9QyAKeFmM9nsN2",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "pzQm1B7UU6QpWMDK4JATW",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
}
],
"section_id": "Wd4FxS3J6O4yAwES20E27"
}
],
"steps": [
"D5zareFNaNbqH7MqA9tM0",
"sSBLzmxxHBK67C8-bwcwt",
"GP9_oCLOI58cqvqWRiwAB",
"9OhCrZ5q4YKxd1iTT_gMj",
"WKe1gv30O8C4aKp8ABTRh",
"-s3GDJC9QyAKeFmM9nsN2"
],
"title": "",
"section_id": "Wd4FxS3J6O4yAwES20E27"
},
{
"id": "xVva0BjGyVM4ihDHFmhfo",
"type": "GROUP",
"items": [
{
"id": "68YvSQ16j1uy33bvAYqwj",
"na": false,
"skip": false,
"type": "TASK ITEM",
"warn": false,
"label": "",
"_group": "xVva0BjGyVM4ihDHFmhfo",
"repeat": 1,
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": "",
"checkbox_label": "Completed"
},
{
"id": "Di-krlCIFct2CPjh3otxn",
"na": false,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "xVva0BjGyVM4ihDHFmhfo",
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": ""
},
{
"id": "WlrESfoGPU2s4Rqu37ydY",
"na": false,
"skip": false,
"type": "TASK ITEM",
"warn": false,
"label": "",
"_group": "xVva0BjGyVM4ihDHFmhfo",
"repeat": 1,
"section_id": "Wd4FxS3J6O4yAwES20E27",
"description": "",
"checkbox_label": "Completed"
}
],
"section_id": "Wd4FxS3J6O4yAwES20E27"
}
],
"steps": [
"tVhFnDUIOnAjW5uBagnEp",
"JeUUbwcSEpSPHqSM_SmUL",
"hsx6tdMuAnSfKXJ1FNV5_",
"6y0kWDg9T4g0DmAzlSOkj",
"MWb-KkigeaJCHUIBMV4YX",
"chY0siMNszJNcdtcFoFIJ",
"t4EX6FpooalFGv0MKr6cv",
"hS-3DZJ3S5fOMo24kH5ZQ",
"FteFQ173r1dfI310xkljO",
"EnEben7GwMCYM4qdGQUN6",
"dDpKHg2E-Vj2UjOZsGiVD",
"68YvSQ16j1uy33bvAYqwj",
"Di-krlCIFct2CPjh3otxn",
"WlrESfoGPU2s4Rqu37ydY"
],
"title": ""
},
{
"id": "vYAk7eXnwjyJaX72cVRmb",
"type": "SECTION",
"items": [
{
"id": "ykpItUktwJvRZTfLGUaQ5",
"type": "GROUP",
"items": [
{
"id": "lsxj_K_Cu-dTOXeMy6N1r",
"na": true,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "ykpItUktwJvRZTfLGUaQ5",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"description": ""
},
{
"id": "-Uum_WruYDefivd3iTC_A",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "ykpItUktwJvRZTfLGUaQ5",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
}
],
"section_id": "vYAk7eXnwjyJaX72cVRmb"
},
{
"id": "UcV8YBrF9SgI13fZZu7S7",
"type": "SUB-SECTION",
"items": [
{
"id": "2IOdE_PjqEtvlVLg4xjP8",
"type": "GROUP",
"items": [
{
"id": "dXho5RxV1mqIYD7esfhmq",
"na": false,
"skip": false,
"type": "PASS/FAIL",
"warn": false,
"label": "",
"_group": "2IOdE_PjqEtvlVLg4xjP8",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"description": ""
},
{
"id": "3_TOIjyYcqd_dP2fIgcoQ",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "2IOdE_PjqEtvlVLg4xjP8",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
}
],
"section_id": "vYAk7eXnwjyJaX72cVRmb"
},
{
"id": "5BMP1oU6RX_OUwUfm61ry",
"type": "INSTRUCTION",
"title": "",
"content": "",
"infoPanel": "none",
"section_id": "vYAk7eXnwjyJaX72cVRmb"
},
{
"id": "6lSvHOLIykr43zthdaQBG",
"url": "",
"type": "CUSTOM",
"label": "",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"description": "",
"configuration": ""
}
],
"steps": [
"dXho5RxV1mqIYD7esfhmq",
"3_TOIjyYcqd_dP2fIgcoQ",
"5BMP1oU6RX_OUwUfm61ry",
"6lSvHOLIykr43zthdaQBG"
],
"title": "",
"section_id": "vYAk7eXnwjyJaX72cVRmb"
},
{
"id": "NdQu7KDZAzHgC0kV2a5N9",
"type": "GROUP",
"items": [
{
"id": "ln6JCUpOIIy2dddDv6ZcI",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "NdQu7KDZAzHgC0kV2a5N9",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
},
{
"id": "j7l8s3g8wEp7s3PUW2v-q",
"na": false,
"skip": false,
"type": "YES/NO",
"warn": false,
"label": "",
"_group": "NdQu7KDZAzHgC0kV2a5N9",
"section_id": "vYAk7eXnwjyJaX72cVRmb",
"test_types": "AFFIRMATIVE_PASS",
"description": ""
}
],
"section_id": "vYAk7eXnwjyJaX72cVRmb"
}
],
"steps": [
"lsxj_K_Cu-dTOXeMy6N1r",
"-Uum_WruYDefivd3iTC_A",
"UcV8YBrF9SgI13fZZu7S7",
"ln6JCUpOIIy2dddDv6ZcI",
"j7l8s3g8wEp7s3PUW2v-q"
],
"title": "Second Test"
},
{
"id": "_87hP9cL5MUJP_j1POR4b",
"type": "SECTION",
"items": [],
"steps": [],
"title": ""
}
]
}
How do I extract all the steps (only steps) from the above JSON
?
How do I extract all the steps and their group ID's and section ID's using postgres query?
I have used recursive CTE's so far, but I'm getting either one of these errors, "could not identify an equality operator for type json" or "ERROR: set-returning functions are not allowed in CASE". I have even changed column type from json to jsonb and viceversa.
Here's what I have used so far,
WITH RECURSIVE procedures (json_element) AS (
-- non recursive term
SELECT
column_i_want
FROM from_table WHERE system_id = 'abc'
UNION
-- recursive term
SELECT
CASE
WHEN jsonb_typeof(json_element) = 'array' OR jsonb_typeof(json_element) = 'object'
THEN jsonb_array_elements_text(json_element)
WHEN jsonb_exists(json_element, 'steps')
THEN jsonb_array_elements_text(json_element -> 'steps')
END AS json_element
FROM
procedures
WHERE
jsonb_typeof(json_element) = 'array' OR jsonb_typeof(json_element) = 'object'
)
SELECT * FROM procedures;
I'm using Aurora Serverless with version (psql (13.3, server 12.8))
Any help is greatly appreciated..! Thanks.

How do I strip this JSON in Angular?

I have a JSON, from which I need to strip down the name and position values of every subFolder to picture the folder structure from inside the JSON in a ngx-treeview in Angular.
I only want to have the subFolders, including the templates in the subFolders. Since the structure of the JSON object doesn't exactly match at all places and is not homogenous.
How do I dynamically push the subFolder values into the treeview (ngx-treeview) in the exact folder structure from the JSON?
The ngx-treeview JSON should look something like this:
templates = new TreeviewItem({
text: "Abrechnung",
value: 1,
children: [
{
text: "Fahrtkosten",
value: 11,
},
{
text: "Lohn",
value: 12,
},
],
});
My JSON:
{
"soap:Envelope": {
"soap:Body": {
"ns2:getTemplateTreeResponse": {
"return": {
"subFolders": {
"name": "Vorlagen",
"description": "",
"subFolders": {
"name": "VorlagenB",
"description": "",
"subFolders": [
{
"name": "Abrechnung",
"description": "",
"subFolders": [
{
"name": "Fahrtkosten",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenzusatz.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Lohn",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Gehaltsabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Lohnbescheid.template",
"description": "",
"metadata": ""
}
]
}
],
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenzusatz.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Gehaltsabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Lohnbescheid.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Datenschutz",
"description": "",
"subFolders": [
{
"name": "Datenschutzbeauftragter",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungHD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungXD.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Datenschutzerklärung",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungKD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungMA.template",
"description": "",
"metadata": ""
}
]
}
],
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungHD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungKD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungMA.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungXD.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Mitarbeiterinfos",
"description": "",
"subFolders": {
"name": "Urlaub",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Template.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantragbescheid.template",
"description": "",
"metadata": ""
}
]
},
"documentTypes": [
{
"fullName": "\\library\\MVP\\Template.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantragbescheid.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Sonstiges",
"description": "",
"subFolders": [
{
"name": "Freitext Briefe",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben1.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben2.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Rückfragen",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Testvorlage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\TestvorlageRgfrage.template",
"description": "",
"metadata": ""
}
]
}
],
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben1.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben2.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Testvorlage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\TestvorlageRgfrage.template",
"description": "",
"metadata": ""
}
]
},
{
"name": "Urlaub",
"description": "",
"subFolders": {
"name": "Urlaubsantrag",
"description": "",
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsanfrage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantrag.template",
"description": "",
"metadata": ""
}
]
},
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsanfrage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantrag.template",
"description": "",
"metadata": ""
}
]
}
],
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben1.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben2.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungHD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungKD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungMA.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungXD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenzusatz.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Gehaltsabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Lohnbescheid.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Template.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Testvorlage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\TestvorlageRgfrage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsanfrage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantrag.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantragbescheid.template",
"description": "",
"metadata": ""
}
]
},
"documentTypes": [
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben1.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Anschreiben2.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungHD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungKD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungMA.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\DatenschutzerklärungXD.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Fahrtkostenzusatz.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Gehaltsabrechnung.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Lohnbescheid.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Template.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Testvorlage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\TestvorlageRgfrage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsanfrage.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantrag.template",
"description": "",
"metadata": ""
},
{
"fullName": "\\library\\MVP\\Vorlagen\\Urlaubsantragbescheid.template",
"description": "",
"metadata": ""
}
]
}
}
}
}
}
}
#evilstiefel was faster than me but I'm with him. Sounds more like a data-transformation issue instead of an Angular one.
See a small StackBlitz sample to see my solution to the problem: https://stackblitz.com/edit/angular-basic-starter-fvewdw?file=src%2Fapp%2Fapp.component.ts
This sounds more like a data analysis problem than an Angular problem. Consider the following helper method that takes your data structure and returns an array which recursively populates a structure that has a folder-name, associated document types and, if present, an array of sub-folders:
const listName = (node: any, aggregate = []): any[] => {
let documentTypes = [];
if (node) {
if (node.documentTypes && node.documentTypes instanceof Array) {
documentTypes = node.documentTypes.map(docType => docType["fullName"]);
}
}
if (node.subFolders && node.subFolders instanceof Array) {
return aggregate.concat({
name: node.name,
documentTypes,
subFolders: node.subFolders.map(folder => listName(folder))
});
} else if (node.subFolders) {
return aggregate.concat({
name: node.name,
documentTypes,
subFolders: [listName(node.subFolders, aggregate)]
});
} else {
return aggregate.concat({ name: node.name, documentTypes, subFolders: [] });
}
};
const tree =
data["soap:Envelope"]["soap:Body"]["ns2:getTemplateTreeResponse"]["return"][
"subFolders"
];
const structure = listName(tree);
There might very well be a shorter version of this recursive function, but it should give you an idea of how to "destructure" your source JSON. Note that in my example, your json-data was loaded into the variable data.

Develop bargraphs from json object list directly

I have multiple json scripts with a similar format as:
{
"name": "xyz",
"slug": "xyz",
"supplier": "xyz.limited",
"attributes": [
{
"name": "mass",
"productConfiguration": "base",
"description": "",
"value": "0.24",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "kg",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "length",
"productConfiguration": "base",
"description": "assumed to be length",
"value": "58.0",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "mm",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "height",
"productConfiguration": "base",
"description": "assumed to be height",
"value": "25.0",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "mm",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "width",
"productConfiguration": "base",
"description": "assumed to be width",
"value": "58.0",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "mm",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "momentum-storage",
"productConfiguration": "base",
"description": "",
"value": "0.050",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "N m s",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "maximum-torque",
"productConfiguration": "base",
"description": "",
"value": "0.007",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "N m",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "voltage",
"productConfiguration": "base",
"description": "voltage is given in DC current",
"value": "12.0",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "V",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "maximum-power",
"productConfiguration": "base",
"description": "",
"value": "9.0",
"minimumValue": "",
"maximumValue": "",
"measurementUnit": "W",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
},
{
"name": "lifetime",
"productConfiguration": "base",
"description": "",
"value": "",
"minimumValue": "5.0",
"maximumValue": "",
"measurementUnit": "yr",
"uuid": "",
"attributeClassUuid": "",
"productUuid": ""
}
]
}
Each of these files have different set of attributes defined. I would like to plot the number of times each attribute is repeated across all files. I try to do this using python3.5 functionalities 'os' and 'panda.DataFrame'. However, got lost somewhere! Can use some help with this. Thanks in advance!

JSON path extractor

I have the following JSON response and I wanted to build the JSON expression to extract the "connectionId" based on given "systemId" and "connectionConfig"."type" value. For example, extract "connectionId" for "systemId"= 'DHB_K8S_HADOOP_SYS' and "connectionConfig"."type"='S3'
{
"browse": [
{
"name": "DHB_K8S_HDFS_Conn1",
"type": "connection",
"connectionId": "DHB_K8S_HDFS_Conn1",
"systemId": "DHB_K8S_HADOOP_SYS",
"uri": "hdfs:///",
"connectionConfig": {
"type": "HDFS",
"description": "",
"connection": "",
"protocol": "",
"authentication": {
"type": "",
"user": "vora"
},
"systemId": "DHB_K8S_HADOOP_SYS",
"zoneId": "DHB_Zone"
},
"children": [
{}
]
},
{
"name": "DHB_K8S_HDFS_S3_Conn1",
"type": "connection",
"connectionId": "DHB_K8S_HDFS_S3_Conn1",
"systemId": "DHB_K8S_HADOOP_SYS",
"uri": "s3a:/",
"connectionConfig": {
"type": "S3",
"description": "",
"connection": "",
"protocol": "",
"authentication": {},
"systemId": "DHB_K8S_HADOOP_SYS",
"zoneId": "DHB_Zone"
},
"children": [
{}
]
},
{
"name": "DHB_K8S_VORA_S3",
"type": "connection",
"connectionId": "DHB_K8S_VORA_S3",
"systemId": "DHB_K8S_VORA_SYS",
"uri": "s3a:/",
"connectionConfig": {
"type": "S3",
"description": "",
"connection": "",
"protocol": "",
"authentication": {},
"systemId": "DHB_K8S_VORA_SYS",
"zoneId": "DHB_Zone"
},
"children": [
{}
]
}
]
}
Any help is appreciated

Convert json to include name and children values to feed D3

I am trying to get json converted from:
{
"Devices": [
{
"Udid": "7a2b0e6c928f2321a75e423ba23ae93d",
"SerialNumber": "RF1D232ZLEE",
"MacAddress": "40F232726FC8",
"Imei": "3576342323280150",
"EasId": "SEC1BC252327E92B",
"AssetNumber": "7a2b0e23223928f2321a75e423ba23ae93d",
"DeviceFriendlyName": "gel1 Android Android 5.0.1 ZLEE ",
"LocationGroupId": {
"Id": {
"Value": 19529
},
"Name": "Group Express"
},
"LocationGroupName": "Group Express",
"UserId": {
"Name": ""
},
"UserName": "",
"UserEmailAddress": "",
"Ownership": "S",
"PlatformId": {
"Id": {
"Value": 5
},
"Name": "Android"
},
"Platform": "Android",
"ModelId": {
"Id": {
"Value": 5
},
"Name": "samsung GT-I9505"
},
"Model": "samsung GT-I9505",
"OperatingSystem": "5.0.1",
"PhoneNumber": "+447881867010",
"LastSeen": "2016-07-06T14:01:03.590",
"EnrollmentStatus": "Unenrolled",
"ComplianceStatus": "NotAvailable",
"CompromisedStatus": false,
"LastEnrolledOn": "2016-06-15T16:01:38.763",
"LastComplianceCheckOn": "0001-01-01T00:00:00.000",
"LastCompromisedCheckOn": "2016-07-06T13:58:26.183",
"IsSupervised": false,
"DeviceMCC": {
"SIMMCC": "234",
"CurrentMCC": "234"
},
"AcLineStatus": 0,
"VirtualMemory": 0,
"Id": {
"Value": 23459
}
},
{
"Udid": "c5f94db71d406dae7f881d3edf059e",
"SerialNumber": "",
"MacAddress": "000C300F9108",
"Imei": "",
"EasId": "D80DB85EC411C8E9B28BC292A603F05C2C0EEEC8",
"AssetNumber": "c592f93db71d406dae7f881d3edf059e",
"DeviceFriendlyName": "user Windows 10 WinRT 10.0.10240 ",
"LocationGroupId": {
"Id": {
"Value": 18498
},
"Name": "Business Solutions"
},
"LocationGroupName": "Business Solutions",
"UserId": {
"Name": ""
},
"UserName": "",
"UserEmailAddress": "",
"Ownership": "C",
"PlatformId": {
"Id": {
"Value": 12
},
"Name": "WinRT"
},
"Platform": "WinRT",
"ModelId": {
"Id": {
"Value": 50
},
"Name": "Windows 10"
},
"Model": "Windows 10",
"OperatingSystem": "10.0.10240",
"PhoneNumber": "",
"LastSeen": "2016-05-03T10:54:07.650",
"EnrollmentStatus": "Unenrolled",
"ComplianceStatus": "NotAvailable",
"CompromisedStatus": false,
"LastEnrolledOn": "2016-01-29T16:41:57.760",
"LastComplianceCheckOn": "0001-01-01T00:00:00.000",
"LastCompromisedCheckOn": "0001-01-01T00:00:00.000",
"IsSupervised": false,
"DeviceMCC": {
"SIMMCC": "",
"CurrentMCC": ""
},
"AcLineStatus": 0,
"VirtualMemory": 0,
"Id": {
"Value": 23545
}
}
],
"Page": 0,
"PageSize": 500,
"Total": 13}
To something like:
{"name": "Devices",
"children": [
{"name":"Udid", "size":"7f0dsda63274692ea4f0b66fec67a020158"},
{"name":"SerialNumber", "size":"P988KJSPQF938"},
{"name":"MacAddress", "size":"1HJUSUD031C4"},
{"name":"Imei", "size":""},
{"name":"EasId", "size":"ApKJSPQF193"},
{"name":"AssetNumber", "size":"7f0cda636b3305fea4f0b66fec9997267a020158"},
{"name":"DeviceFriendlyName", "size":"TMcKenz iPad iOS 7.1.4 F193 "},
{"name":"LocationGroupId",
"children": [
{"name":"Id","size":7488},
{"name":"Name","size":"MCM"}
]
},
{"name":"UserId",
"children": [
{"name":"Id","size":6418},
{"name":"Name","size":"Tom McKenz"}
]
},
{"name":"UserName", "size":"TMcKenz"},
{"name":"UserEmailAddress", "size":"TMcKenz#awaw.com"}
]
}
Not sure what is the best practice here: is it possible to use D3.nest or do you need to iterate through all the nodes and change to 'name' and 'children' accordingly.