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
Related
Hi I have the following JSON file format (sample) and please any one let me know how to open the file in excel columns or tables. Thank you.
{ "fields": [ "id", "name", "definition" ], "items": [ { "ref": "#28:1", "id": "1", "values": [ "1", "ABC", "This is file 1." ], "relationships": [ { "toTable": "Table 1", "relationships": [ { "id": "1", "extra": {} } ] }, { "toTable": "Table 2", "relationships": [ { "id": "1", "extra": {} }, { "id": "7", "extra": {} }, { "id": "11", "extra": {} }, { "id": "24", "extra": {} } ] }, { "toTable": "Table 3", "relationships": [ { "id": "22", "extra": {} }, { "id": "31", "extra": {} } ] }, { "toTable": "Table 4", "relationships": [ { "id": "37", "extra": {} }, { "id": "38", "extra": {} }, { "id": "50", "extra": {} } ] } ] }, { "ref": "#28:2", "id": "2", "values": [ "2", "DEF", "This is file 2." ], "relationships": [ { "toTable": "Table 1", "relationships": [ { "id": "3", "extra": {} } ] }, { "toTable": "Table 2", "relationships": [ { "id": "1", "extra": {} }, { "id": "5", "extra": {} }, { "id": "24", "extra": {} } ] }, { "toTable": "Table 3", "relationships": [ { "id": "1", "extra": {} } ] }, { "toTable": "Table 4", "relationships": [ { "id": "5", "extra": {} }, { "id": "7", "extra": {} } ] } ] }, { "ref": "#28:3", "id": "3", "values": [ "3", "GHI", "This is file 3." ], "relationships": [ { "toTable": "Table 1", "relationships": [ { "id": "1", "extra": {} } ] }, { "toTable": "Table 2", "relationships": [ { "id": "2", "extra": {} }, { "id": "5", "extra": {} }, { "id": "8", "extra": {} } ] }, { "toTable": "Table 4", "relationships": [ { "id": "5", "extra": {} }, { "id": "8", "extra": {} } ] } ] } ], "relatedObjects": [ { "TableId": "Table 1", "totalItems": 151, "totalHits": 1, "fields": [ "id", "Number", "name" ], "items": [ { "ref": "#165:28", "id": "1", "values": [ "1", "ASRU" ] } ] }, { "TableId": "Table 2", "totalItems": 282, "totalHits": 5, "fields": [ "id", "fullName", "firstName" ], "items": [ { "ref": "#68:83", "id": "5", "values": [ "5", "ABC", "Acer" ] } ] } ] }
Tried excel power query to create reports using the above JSON file format.
spreadsheet view, click the “Data” tab on the ribbon at the top of Excel. In the “Data” sections, “Import and Transform” section, select the product from Get Data > From File > JSON. Open your computer's standard "Import" window. Here, open the width where your JSON file is located.
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.
I want to make a search from object JSON but when a I found the element I want to be returned with his previous parents.
[
{
"name": "level1",
"children": [
{
"name": "level2",
"children": [
{
"name": "level3a",
"children": [
{
"name": "text",
"more": "info"
},
{
"name": "text Abc",
"more": "info"
}
]
},
{
"name": "level3b",
"children": [
{
"name": "text-C",
"more": "info"
},
{
"name": "search",
"more": "info"
}
]
},
{
"name": "level3c",
"children": [
{
"name": "info-C",
"more": "info"
},
{
"name": "search",
"more": "info"
}
]
}
]
}
]
},
{
"name": "level1",
"children": [
{
"name": "level2a",
"children": [
{
"name": "level3",
"children": [
{
"name": "text A",
"more": "info"
}
]
},
]
},
{
"name": "level2b",
"children": [
{
"name": "level3",
"children": [
{
"name": "text X",
"more": "info"
}
]
},
]
}
]
}
]
For example: if want to search "text" I want result like this
[
{
"name": "level1",
"children": [
{
"name": "level2",
"children": [
{
"name": "level3a",
"children": [
{
"name": "text",
"more": "info"
},
{
"name": "text Abc",
"more": "info"
}
]
},
{
"name": "level3b",
"children": [
{
"name": "text-C",
"more": "info"
}
]
}
]
}
]
},
{
"name": "level1",
"children": [
{
"name": "level2a",
"children": [
{
"name": "level3",
"children": [
{
"name": "text A",
"more": "info"
}
]
},
]
},
{
"name": "level2b",
"children": [
{
"name": "level3",
"children": [
{
"name": "text X",
"more": "info"
}
]
},
]
}
]
}
]
Things to considerer
only "search" in level 3 children by name property
if one o more childrens matches the search, return all of them
Basically I need to filter by the last level of object with elements matches with the search and return them with them parents.
I have an elastic search index
like
{
"title": "A",
"comments": [
{
"id": "1"
},
{
"id": "2"
}
]
},
{
"title": "B",
"comments": [
{
"id": "1"
},
{
"id": "3"
}
]
},
{
"title": "C",
"comments": [
{
"id": "7"
},
{
"id": "3"
}
]
}
I want to collapse is the group by the nested object. In the above JSON, I want to group it by Id.
So the output will be like
hits:[{
"title": "A",
"comments": [
{
"id": "1"
},
{
"id": "2"
}
]
},
inner_hits {[
{
"title": "A",
"comments": [
{
"id": "1"
},
{
"id": "2"
}
]
},
{
"title": "B",
"comments": [
{
"id": "1"
},
{
"id": "3"
}
]
}
]}
}]
Baiscally I need collapse bases on the nested object property.
Tried this
/_search?track_total_hits=true
{
"collapse": {
"field": "comments.id",
"inner_hits": {
"name": "id",
"size": 10
},
"max_concurrent_group_searches": 3
}
}
But its always returing first object only in the inner hits
Within the mapping of the object comments , you should remove the nested type.
just checking before i build the wheel
I need a hackjob to present an api endpoint in a database. It doesn't need to do anything fancy, just convert what the rest api spits out into a single column of json. A new row at each iteration at the root/top level would be nice but a single varchar or whatever would be ok too
Does an ODBC wrapper exist out there anywhere? Googling just brings up hits for doing the opposite (exposing databases as an api). I'm not interested in the simba etc paid stuff. The consumer is SQL server so i can just use xp_cmdshell with curl as a last resort
so for instance the output of this : http://jsonapiplayground.reyesoft.com/v2/authors could come out as a table like so (a row for each author)
|data |
---------------------------------------------------
|{
"type": "authors",
"id": "1",
"attributes": {
"name": "Madge Mohr DVM 2",
"date_of_birth": "1977-08-21",
"date_of_death": "2009-09-14"
},
"relationships": {
"photos": {
"data": []
},
"books": {
"data": [
{
"type": "books",
"id": "41"
}
]
}
},
"links": {
"self": "/v2/authors/1"
}
} |
---------------------------------------------------
|{
"type": "authors",
"id": "3",
"attributes": {
"name": "Zelma Ortiz DDS",
"date_of_birth": "1992-09-06",
"date_of_death": "2000-12-19"
},
"relationships": {
"photos": {
"data": [
{
"type": "photos",
"id": "3"
}
]
},
"books": {
"data": [
{
"type": "books",
"id": "36"
},
{
"type": "books",
"id": "48"
}
]
}
},
"links": {
"self": "/v2/authors/3"
}
}|
----------
|{
"type": "authors",
"id": "4",
"attributes": {
"name": "Fermin Barrows Sr.",
"date_of_birth": "1991-03-18",
"date_of_death": "1975-11-07"
},
"relationships": {
"photos": {
"data": [
{
"type": "photos",
"id": "4"
}
]
},
"books": {
"data": [
{
"type": "books",
"id": "1"
},
{
"type": "books",
"id": "26"
},
{
"type": "books",
"id": "44"
},
{
"type": "books",
"id": "46"
}
]
}
},
"links": {
"self": "/v2/authors/4"
}
}|
----------
|{
"type": "authors",
"id": "5",
"attributes": {
"name": "Terry Durgan",
"date_of_birth": "2011-03-06",
"date_of_death": "2017-04-13"
},
"relationships": {
"photos": {
"data": [
{
"type": "photos",
"id": "5"
}
]
},
"books": {
"data": [
{
"type": "books",
"id": "6"
},
{
"type": "books",
"id": "16"
},
{
"type": "books",
"id": "50"
}
]
}
},
"links": {
"self": "/v2/authors/5"
}
}|
----------
|{
"type": "authors",
"id": "6",
"attributes": {
"name": "Annalise Walsh",
"date_of_birth": "2004-11-27",
"date_of_death": "1997-07-20"
},
"relationships": {
"photos": {
"data": [
{
"type": "photos",
"id": "6"
}
]
},
"books": {
"data": [
{
"type": "books",
"id": "4"
},
{
"type": "books",
"id": "5"
},
{
"type": "books",
"id": "21"
}
]
}
},
"links": {
"self": "/v2/authors/6"
}
}|
---------