Dependent field in another dependent field - json

I have a form with dependent fields that works fine, but now I'm trying to add a second dependent field, that will rely on my first dependent field:
{
"job_level": {
"type": "select",
"label": "Job Level",
"order": 8,
"state": "required",
"selection_values": [
{
"id": "",
"label": "* Job Level"
},
{
"id": "c_level",
"label": "C-Level"
},
{
"id": "architect",
"label": "Architect"
}
]
},
"job_function": {
"type": "select",
"label": "Job Function",
"order": 9,
"state": "required",
"dependent_field": {
"name": "job_level",
"values": [
"c_level",
"architect"
]
},
"selection_values": {
"c_level": [
{
"id": "",
"label": "* Job Function"
},
{
"id": "Security",
"label": "Security"
},
{
"id": "HR",
"label": "HR"
}
],
"architect": [
{
"id": "",
"label": "* Job Function"
},
{
"id": "Sales",
"label": "Sales"
}
]
}
},
"job_role": {
"type": "select",
"label": "Job Role",
"order": 10,
"state": "required",
"dependent_field": {
"name": "job_function",
"values": [
"Security",
"HR",
"Sales"
]
},
"selection_values": {
"Security": [
{
"id": "",
"label": "* Job Role"
},
{
"id": "CISO",
"label": "CISO"
},
{
"id": "CSO",
"label": "CSO"
},
{
"id": "Other",
"label": "Other"
}
],
"HR": [
{
"id": "",
"label": "* Job Role"
},
{
"id": "CHRO",
"label": "CHRO"
},
{
"id": "Other",
"label": "Other"
}
],
"Sales": [
{
"id": "",
"label": "* Job Role"
},
{
"id": "Operations_Sales",
"label": "Operations/Sales"
},
{
"id": "Other",
"label": "Other"
}
]
}
}
}
job_role is the field I'm trying to add, but when I'm selecting a Job Function in the form, the field is not appearing in the form. Any thoughts? Thanks.

Related

Flatten a JSON document using jq by filtering an array by keys

I have a JSON in the following format:
{
"subFields": [
{
"id": "question_1",
"type": "radioGroup",
"description": "Description1",
"title": "title1",
"subFields": [
{
"type": "radio",
"label": "Yes",
"value": 1
},
{
"type": "radio",
"label": "No",
"value": 0
},
{
"uiComponent": "SmallContent",
"componentProps": {
"text": "* If the answer to the above question is “Yes”, please contact the Support immediately."
}
}
]
},
{
"uiComponent": "Spacer"
},
{
"id": "question_2",
"type": "radioGroup",
"description": "Description2",
"title": "Title2",
"subFields": [
{
"type": "radio",
"label": "Label - Value 1",
"value": 1
},
{
"type": "radio",
"label": "Label - Value 2",
"value": 2
},
{
"type": "radio",
"label": "Label - Value 3",
"value": 3
},
{
"type": "radio",
"label": "Other",
"value": 13,
"subFields": [
{
"id": "question_2a",
"type": "string",
"condition": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "question_2"
},
"right": {
"type": "Literal",
"value": 13
}
}
}
]
}
]
},
{
"id": "question_2_b",
"style": {
"marginTop": "30px"
},
"type": "radioGroup",
"description": "Description3",
"title": "",
"subFields": [
{
"type": "radio",
"label": "Label - Radio 1",
"value": 1
},
{
"type": "radio",
"label": "Label - Radio 2",
"value": 2
},
{
"type": "radio",
"label": "Label - Radio 3",
"value": 3
}
]
},
{
"uiComponent": "Spacer"
},
{
"id": "question_3",
"type": "radioGroup",
"description": "Description3",
"title": "Title3",
"subFields": [
{
"type": "radio",
"label": "Yes",
"value": 1
},
{
"type": "radio",
"label": "No",
"value": 0
}
]
},
{
"uiComponent": "Spacer"
},
{
"condition": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "signer_type"
},
"right": {
"type": "Literal",
"value": "entity"
}
},
"subFields": [
{
"uiComponent": "Spacer"
},
{
"id": "question_4",
"type": "radioGroup",
"description": "Description_4",
"title": "Title_4",
"subFields": [
{
"type": "radio",
"label": "Yes",
"value": 1
},
{
"type": "radio",
"label": "No",
"value": 0
}
]
},
{
"uiComponent": "Spacer"
}
],
"uiComponent": "Block"
},
{
"uiComponent": "Spacer"
}
],
"uiComponent": "Container"
}
and I would like to generate the following output:
[
{
"id": "question_1",
"title": "title1",
"description": "Description1",
"type": "radioGroup",
"questions": "radio,Yes,1"
},
{
"id": "question_1",
"title": "title1",
"description": "Description1",
"type": "radioGroup",
"questions": "radio,No,0"
},
{
"id": "question_2",
"title": "Title2",
"description": "Description2",
"type": "radioGroup",
"questions": "radio,Label - Value 1,1"
},
{
"id": "question_2",
"title": "Title2",
"description": "Description2",
"type": "radioGroup",
"questions": "radio,Label - Value 2,2"
},
{
"id": "question_2",
"title": "Title2",
"description": "Description2",
"type": "radioGroup",
"questions": "radio,Label - Value 3,3"
},
{
"id": "question_2_b",
"title": "",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,Label - Value 1,1"
},
{
"id": "question_2_b",
"title": "",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,Label - Value 2,2"
},
{
"id": "question_2_b",
"title": "",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,Label - Value 3,3"
},
{
"id": "question_3",
"title": "Title3",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,Yes,1"
},
{
"id": "question_3",
"title": "Title3",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,No,0"
}
]
or in alternative a reduced version:
[
"question_1",
"title1",
"Description1",
"radioGroup",
"radio,Yes,1",
"radio,No,0"
],
[
"question_2",
"title2",
"Description2",
"radioGroup",
"radio,Label - Value 1,1",
"radio,Label - Value 2,2",
"radio,Label - Value 3,3",
],
[
"question_2_b",
"Description3",
"radioGroup",
"radio,Label - Value 1,1",
"radio,Label - Value 2,2",
"radio,Label - Value 3,3",
],
[
"question_3",
"Title3",
"Description3",
"radioGroup",
"radio,Yes,1",
"radio,No,0"
]
The objective is to get only the objects that contain the id (to remove the {"uiComponent": "Spacer"} objects) and get only the subFields with these tags inside the array:
"subFields": [
{
"type": "xxxx",
"label": "xxxx",
"value": xxxx
},
I was able to flatten the JSON array by using the following JQ pattern:
jq play 1
.subFields[] | select(has("id") and .id != null)| {id: .id, type: .type, description: .description, anwers: .subFields}
and generated this result:
{
"id": "question_1",
"type": "radioGroup",
"description": "Description1",
"anwers": [
{
"type": "radio",
"label": "Yes",
"value": 1
},
{
"type": "radio",
"label": "No",
"value": 0
},
{
"uiComponent": "SmallContent",
"componentProps": {
"text": "* If the answer to the above question is “Yes”, please contact the Support immediately."
}
}
]
}
{
"id": "question_2",
"type": "radioGroup",
"description": "Description2",
"anwers": [
{
"type": "radio",
"label": "Label - Value 1",
"value": 1
},
{
"type": "radio",
"label": "Label - Value 2",
"value": 2
},
{
"type": "radio",
"label": "Label - Value 3",
"value": 3
},
{
"type": "radio",
"label": "Other",
"value": 13,
"subFields": [
{
"id": "question_2a",
"type": "string",
"condition": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "question_2"
},
"right": {
"type": "Literal",
"value": 13
}
}
}
]
}
]
}
{
"id": "question_2_b",
"type": "radioGroup",
"description": "Description3",
"anwers": [
{
"type": "radio",
"label": "Label - Radio 1",
"value": 1
},
{
"type": "radio",
"label": "Label - Radio 2",
"value": 2
},
{
"type": "radio",
"label": "Label - Radio 3",
"value": 3
}
]
}
{
"id": "question_3",
"type": "radioGroup",
"description": "Description3",
"anwers": [
{
"type": "radio",
"label": "Yes",
"value": 1
},
{
"type": "radio",
"label": "No",
"value": 0
}
]
}
My problem is that I don't know how to remove these sections:
{
"uiComponent": "SmallContent",
"componentProps": {
"text": "* If the answer to the above question is “Yes”, please contact the Support immediately."
}
}
and
"subFields": [
{
"id": "question_2a",
"type": "string",
"condition": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "question_2"
},
"right": {
"type": "Literal",
"value": 13
}
}
}
]
I played a little bit arround with this jq for the question_3 only:
jq play 2
.subFields[] | {id: .id, title: .title, description: .description, type: .type, subFields: .subFields} | select(has("id") and .id != null) | select(.id=="question_3") | {id: .id, title: .title, description: .description, type: .type, questions: (.subFields[]|join(","))}
and produced this result:
{
"id": "question_3",
"title": "Title3",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,Yes,1"
}
{
"id": "question_3",
"title": "Title3",
"description": "Description3",
"type": "radioGroup",
"questions": "radio,No,0"
}
and also
jq play 3
.subFields[] | {id: .id, title: .title, description: .description, type: .type, subFields: .subFields} | select(has("id") and .id != null) | select(.id=="question_3") | [.id, .title, .description, .type, (.subFields[]|join(","))]
resulting on this:
[
"question_3",
"Title3",
"Description3",
"radioGroup",
"radio,Yes,1",
"radio,No,0"
]
Can you help me improve those JQ pattern I created to get the intended results?
Thanks in advance!
The following produces your first alternative:
.subFields[]
| select(.id?)
| { id, title, description, type} +
(.subFields[]
| select(.type?)
| [.type,.label,.value] | join(",")
| { questions: .} )
Notice the two select() filters.
The key names are specified explicitly here to ensure the ordering you specified is honored.

How to extract the path info?

For the following JSON, I'd like to extract something like this ( is a TAB character).
CHROMOSOMES<TAB>HUMAN<TAB>1<TAB>1
...
STATUSES<TAB>name<TAB>Approved
...
ATTRIBUTES<TAB>HGNC<TAB>HGNC ID<TAB>gd_hgnc_id
...
ATTRIBUTES<TAB>EXTERNAL<TAB>NCBI Gene ID<TAB>md_eg_id<TAB>NCBI
...
ORDER_BY<TAB>HGNC ID<TAB>gd_hgnc_id
...
I'd like a smart way to extract the path info of this tree structure. Could you anybody show me the best way to do so? Thanks.
{
"CHROMOSOMES": {
"HUMAN": [
{
"name": "1",
"value": "1"
},
{
"name": "2",
"value": "2"
},
{
"name": "3",
"value": "3"
},
{
"name": "4",
"value": "4"
},
{
"name": "5",
"value": "5"
},
{
"name": "6",
"value": "6"
},
{
"name": "7",
"value": "7"
},
{
"name": "8",
"value": "8"
},
{
"name": "9",
"value": "9"
},
{
"name": "10",
"value": "10"
},
{
"name": "11",
"value": "11"
},
{
"name": "12",
"value": "12"
},
{
"name": "13",
"value": "13"
},
{
"name": "14",
"value": "14"
},
{
"name": "15",
"value": "15"
},
{
"name": "16",
"value": "16"
},
{
"name": "17",
"value": "17"
},
{
"name": "18",
"value": "18"
},
{
"name": "19",
"value": "19"
},
{
"name": "20",
"value": "20"
},
{
"name": "21",
"value": "21"
},
{
"name": "22",
"value": "22"
},
{
"name": "X",
"value": "X"
},
{
"name": "Y",
"value": "Y"
},
{
"name": "reserved loci",
"value": "reserved"
},
{
"name": "mitochondrial",
"value": "mito"
},
{
"name": "pseudoautosomal",
"value": "XandY"
}
]
},
"STATUSES": [
{
"name": "Approved",
"value": "Approved"
},
{
"name": "Entry and symbol withdrawn",
"value": "Entry Withdrawn"
}
],
"ATTRIBUTES": {
"HGNC": [
{
"name": "HGNC ID",
"value": "gd_hgnc_id"
},
{
"name": "Approved symbol",
"value": "gd_app_sym"
},
{
"name": "Approved name",
"value": "gd_app_name"
},
{
"name": "Status",
"value": "gd_status"
},
{
"name": "Locus type",
"value": "gd_locus_type"
},
{
"name": "Locus group",
"value": "gd_locus_group"
},
{
"name": "Previous symbols",
"value": "gd_prev_sym"
},
{
"name": "Previous name",
"value": "gd_prev_name"
},
{
"name": "Synonyms",
"value": "gd_aliases"
},
{
"name": "Name synonyms",
"value": "gd_name_aliases"
},
{
"name": "Chromosome",
"value": "gd_pub_chrom_map"
},
{
"name": "Date approved",
"value": "gd_date2app_or_res"
},
{
"name": "Date modified",
"value": "gd_date_mod"
},
{
"name": "Date symbol changed",
"value": "gd_date_sym_change"
},
{
"name": "Date name changed",
"value": "gd_date_name_change"
},
{
"name": "Accession numbers",
"value": "gd_pub_acc_ids"
},
{
"name": "Enzyme IDs",
"value": "gd_enz_ids"
},
{
"name": "NCBI Gene ID",
"value": "gd_pub_eg_id"
},
{
"name": "Ensembl gene ID",
"value": "gd_pub_ensembl_id"
},
{
"name": "Mouse genome database ID",
"value": "gd_mgd_id"
},
{
"name": "Specialist database links",
"value": "gd_other_ids"
},
{
"name": "Specialist database IDs",
"value": "gd_other_ids_list"
},
{
"name": "Pubmed IDs",
"value": "gd_pubmed_ids"
},
{
"name": "RefSeq IDs",
"value": "gd_pub_refseq_ids"
},
{
"name": "Gene group ID",
"value": "family.id"
},
{
"name": "Gene group name",
"value": "family.name"
},
{
"name": "CCDS IDs",
"value": "gd_ccds_ids"
},
{
"name": "Vega IDs",
"value": "gd_vega_ids"
},
{
"name": "Locus specific databases",
"value": "gd_lsdb_links"
}
],
"EXTERNAL": [
{
"name": "NCBI Gene ID",
"source": "NCBI",
"value": "md_eg_id"
},
{
"name": "OMIM ID",
"source": "OMIM",
"value": "md_mim_id"
},
{
"name": "RefSeq",
"source": "NCBI",
"value": "md_refseq_id"
},
{
"name": "UniProt ID",
"source": "UniProt",
"value": "md_prot_id"
},
{
"name": "Ensembl ID",
"source": "Ensembl",
"value": "md_ensembl_id"
},
{
"name": "Vega ID",
"source": "Vega",
"value": "md_vega_id"
},
{
"name": "UCSC ID",
"source": "UCSC",
"value": "md_ucsc_id"
},
{
"name": "Mouse genome database ID",
"source": "MGI",
"value": "md_mgd_id"
},
{
"name": "Rat genome database ID",
"source": "RGD",
"value": "md_rgd_id"
},
{
"name": "LNCipedia",
"source": "LNCipedia",
"value": "md_lncipedia"
},
{
"name": "GtRNAdb",
"source": "GtRNAdb",
"value": "md_gtrnadb"
}
]
},
"ORDER_BY": [
{
"name": "HGNC ID",
"value": "gd_hgnc_id"
},
{
"name": "Approved symbol",
"value": "gd_app_sym_sort"
},
{
"name": "Approved name",
"value": "gd_app_name"
},
{
"name": "Status",
"value": "gd_status"
},
{
"name": "Locus type",
"value": "gd_locus_type"
},
{
"name": "Locus group",
"value": "gd_locus_group"
},
{
"name": "Previous symbols",
"value": "gd_prev_sym"
},
{
"name": "Previous name",
"value": "gd_prev_name"
},
{
"name": "Synonyms",
"value": "gd_aliases"
},
{
"name": "Name synonyms",
"value": "gd_name_aliases"
},
{
"name": "Chromosome",
"value": "gd_pub_chrom_map_sort"
},
{
"name": "Date approved",
"value": "gd_date2app_or_res"
},
{
"name": "Date modified",
"value": "gd_date_mod"
},
{
"name": "Date symbol changed",
"value": "gd_date_sym_change"
},
{
"name": "Date name changed",
"value": "gd_date_name_change"
},
{
"name": "Accession numbers",
"value": "gd_pub_acc_ids"
},
{
"name": "Enzyme IDs",
"value": "gd_enz_ids"
},
{
"name": "NCBI Gene ID",
"value": "gd_pub_eg_id"
},
{
"name": "Ensembl gene ID",
"value": "gd_pub_ensembl_id"
},
{
"name": "Mouse genome database ID",
"value": "gd_mgd_id"
},
{
"name": "Specialist database links",
"value": "gd_other_ids"
},
{
"name": "Specialist database IDs",
"value": "gd_other_ids_list"
},
{
"name": "Pubmed IDs",
"value": "gd_pubmed_ids"
},
{
"name": "RefSeq IDs",
"value": "gd_pub_refseq_ids"
},
{
"name": "Gene group ID",
"value": "family.id"
},
{
"name": "Gene group name",
"value": "family.name"
},
{
"name": "CCDS IDs",
"value": "gd_ccds_ids"
},
{
"name": "Vega IDs",
"value": "gd_vega_ids"
},
{
"name": "Locus specific databases",
"value": "gd_lsdb_links"
},
{
"name": "NCBI Gene ID (supplied by NCBI)",
"value": "md_eg_id"
},
{
"name": "OMIM ID (supplied by OMIM)",
"value": "md_mim_id"
},
{
"name": "RefSeq (supplied by NCBI)",
"value": "md_refseq_id"
},
{
"name": "UniProt ID (supplied by UniProt)",
"value": "md_prot_id"
},
{
"name": "Ensembl ID (supplied by Ensembl)",
"value": "md_ensembl_id"
},
{
"name": "Vega ID (supplied by Vega)",
"value": "md_vega_id"
},
{
"name": "UCSC ID (supplied by UCSC)",
"value": "md_ucsc_id"
},
{
"name": "Mouse genome database ID (supplied by MGI)",
"value": "md_mgd_id"
},
{
"name": "Rat genome database ID (supplied by RGD)",
"value": "md_rgd_id"
},
{
"name": "LNCipedia ID (supplied by LNCipedia)",
"value": "md_lncipedia"
},
{
"name": "GtRNAdb ID (supplied by GtRNAdb)",
"value": "md_gtrnadb"
}
],
"OUTPUT": [
"Text",
"Make URL for text"
]
}
I'd like a smart way to extract the path info of this tree structure.
paths is your friend.
Given certain irregularities in the input, the exact requirements are
not always clear, but the following might be what you are looking for
and even if not, it would be easy to tweak in accordance with your
detailed requirements.
totsv.jq
def s: map(select(type=="string"));
paths as $p
| getpath($p)
| if type == "object" and has("name")
then ($p|s) + [.name, .value, (.source // empty)]
elif type == "array" and .[0] == "Text" then ($p|s) + .
else empty
end
| #tsv
Invocation
jq -crf totsv.jq chromosomes.json
Selection from output
CHROMOSOMES HUMAN 1 1
CHROMOSOMES HUMAN 2 2
...
STATUSES Approved Approved
STATUSES Entry and symbol withdrawn Entry Withdrawn
ATTRIBUTES HGNC HGNC ID gd_hgnc_id
...
ORDER_BY GtRNAdb ID (supplied by GtRNAdb) md_gtrnadb
OUTPUT Text Make URL for text
For future reference
Rather than give a very long sample input, it would be better
to give a small sample that is tightly woven with detailed requirements.

unable to extract value using ._find

I have the following node.js code where I want to extract the value "abc" chosen by user as a name. I get result as undefined when I run this code:
let input= [
{
"param": [
{
"id": "name",
"choice": [
{
"label": "abc",
"value": "abc",
"valueId": "abc"
}
]
},
{
"id": "alias",
"choice": [
{
"label": "dsf",
"value": "dsf",
"valueId": "dsf"
}
]
},
{
"id": "description",
"choice": [
{
"label": "",
"value": "",
"valueId": ""
}
]
},
{
"id": "Key",
"choice": [
{
"label": "K",
"value": "K",
"valueId": "K"
}
]
},
{
"id": "tagKey",
"choice": [
{
"label": "",
"value": "",
"valueId": ""
}
]
},
{
"id": "tagValue",
"choice": [
{
"label": "",
"value": "",
"valueId": ""
}
]
},
{
"id": "multiquantity",
"choice": [
{
"label": "1",
"valueId": "1",
"value": "1"
}
]
}
],
"old": [],
"current": null
}
]
let result = (_.find(input.param, {id: "name"})).choice[0].valueId;
console.log("value"+result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
Seems that the logic is not able to extract the correct value. I need the output as abc. please help

JSON values not displaying if objects are nested

Here is my code:
<tbody class="mat-color--white tdw-card-thin tdw-border-2">
<tr class="tdw-hover-up-thin" *ngFor="let item of _mData | tdwSearchfilter: _mSearchField: _mSearchQuery | orderBy: order:reverse:'case-insensitive'; let iRow=index">
<th *ngIf="_mIsCheckable" class="tdw--text-align-right sort-remove">
<mat-checkbox [(ngModel)]="_mIsCheckedList[i]" ></mat-checkbox>
</th>
<th class="tdw-bottom-line-light tdw-padding-v-16 tdw-font-14 tdw-font-open-sans tdw-font-normal mat-color-text--grey-800"
*ngFor="let prop of _mColumns">{{item[prop.key]}}</th>
<th class=" tdw-bottom-line-light tdw-text-align-right" *ngIf="_mOptions">
<button mat-icon-button [matMenuTriggerFor]="optionMenu" (menuClosed)="onMenuClosed(iRow)">
<mat-icon>more_vert</mat-icon>
</button>
</th>
</tr>
</tbody>
and Typescript file will have following data fetched from server.
on server call am assigning these values
this._mColumns = this.tempData.headers;//success.headers;
this._mData = this.tempData.dataList.content;//success.dataList.content;
backend data:
tempData = {
"headers": [
{
"label": "User name",
"key": "userName"
},
{
"label": "First name",
"key": "userInfoDetails.firstName"
},
{
"label": "Middle name",
"key": "userInfoDetails.middleName"
},
{
"label": "Last name",
"key": "userInfoDetails.lastName"
},
{
"label": "Gender",
"key": "userInfoDetails.gender"
},
{
"label": "Personal number",
"key": "userInfoDetails.personalNumber"
},
{
"label": "Email",
"key": "userInfoDetails.emailAddress"
},
{
"label": "Home country",
"key": "userInfoDetails.homeCountry"
},
{
"label": "Career Level",
"key": "userInfoDetails.careerLevel"
},
{
"label": "Career PathwayDesc",
"key": "userInfoDetails.careerPathwayDesc"
},
{
"label": "Business UnitCode",
"key": "userInfoDetails.businessUnitCode"
},
{
"label": "business UnitDescription",
"key": "userInfoDetails.businessUnitDescription"
},
{
"label": "Dept number",
"key": "userInfoDetails.deptNumber"
},
{
"label": "Dept name",
"key": "userInfoDetails.deptName"
},
{
"label": "Operation Code",
"key": "userInfoDetails.operationCode"
},
{
"label": "Operation Description",
"key": "userInfoDetails.operationDescription"
},
{
"label": "DateOf joining",
"key": "userInfoDetails.dateOfJoining"
},
{
"label": "Address",
"key": "userInfoDetails.address"
},
{
"label": "Is contract employee",
"key": "userInfoDetails.isContractEmployee"
},
{
"label": "State",
"key": "userInfoDetails.state"
},
{
"label": "Contact number",
"key": "userInfoDetails.contactNumber"
},
{
"label": "Site name",
"key": "userInfoDetails.site.siteName"
}],
"dataList": {
"content": [
{
"userName": "Syed",
"userInfoDetails": {
"id": 1,
"firstName": "Syed", "middleName": "Akmal", "lastName": "Pasha",
"gender": "male", "personalNumber": 9589489884, "emailAddress": "syed#gmail.com",
"homeCountry": "India"
}
},
{
"userName": "Ryan",
"userInfoDetails": {
"id": 2,
"firstName": "Ryan", "middleName": "Sheiq", "lastName": "Samar",
"gender": "male", "personalNumber": 9589489848, "emailAddress": "syed#gmail.com",
"homeCountry": "Dubai"
}
}
],
"last": true,
"totalPages": 1,
"totalElements": 2,
"size": 20,
"number": 0,
"first": true,
"sort": null,
"numberOfElements": 2
}
};
The issue is it's not able to display the nested object like "userInfoDetails.firstName" but its showing the content of immediate object but not the child object.

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.