ich die folgende JSON-Daten haben:ersetzen Werte in Json
[
{
"item": {
"name": "tso",
"type": "table",
"displayName": "TSO",
"operators": [
"in",
"not in",
"=",
"<>"
],
"values": []
},
"operator": "in",
"value": [
"NL"
],
"conjunction": " ",
"level": 0,
"userFriendlyValue": [
"TENNET_NL"
]
},
{
"item": {
"name": "elementType",
"type": "select",
"displayName": "Element type",
"operators": [
"=",
"<>"
],
"values": [
"line",
"trafo"
]
},
"operator": "=",
"value": "line",
"conjunction": "and",
"level": 1,
"userFriendlyValue": null
},
{
"item": {
"name": "optionalName",
"type": "table",
"displayName": "Element optional name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "like",
"value": "*110*",
"conjunction": "and",
"level": 2,
"userFriendlyValue": null
},
{
"item": {
"name": "optionalName",
"type": "table",
"displayName": "Element optional name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "like",
"value": "*150*",
"conjunction": "or",
"level": 2,
"userFriendlyValue": null
},
{
"item": {
"name": "optionalName",
"type": "table",
"displayName": "Element optional name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "like",
"value": "KV_VS",
"conjunction": "or",
"level": 2,
"userFriendlyValue": null
},
{
"item": {
"name": "elementName",
"type": "table",
"displayName": "Element name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "like",
"value": "*15*",
"conjunction": "or",
"level": 2,
"userFriendlyValue": null
},
{
"item": {
"name": "elementName",
"type": "table",
"displayName": "Element name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "like",
"value": "*11*",
"conjunction": "or",
"level": 2,
"userFriendlyValue": null
},
{
"item": {
"name": "elementName",
"type": "table",
"displayName": "Element name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "in",
"value": [
"NEHVN_3_NOIRSC3_1",
"NGNHU_5_NGNHU_5_1",
"NMVL381_NMDC381_1",
"XGR_MA1_NMDC381_1"
],
"conjunction": "or",
"level": 2,
"userFriendlyValue": [
"NEHVN_3_NOIRSC3_1",
"NGNHU_5_NGNHU_5_1",
"NMVL381_NMDC381_1",
"XGR_MA1_NMDC381_1"
]
},
{
"item": {
"name": "elementType",
"type": "select",
"displayName": "Element type",
"operators": [
"=",
"<>"
],
"values": [
"line",
"trafo"
]
},
"operator": "=",
"value": "trafo",
"conjunction": "or",
"level": 1,
"userFriendlyValue": null
},
{
"item": {
"name": "elementName",
"type": "table",
"displayName": "Element name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "in",
"value": [
"NBSL381_NBSL381_U",
"NBSL381_NBSL381_V",
"NBWK381_NBWK381_U",
"NBWK381_NBWK381_W",
"NBWK381_NBWK381_Y",
"NCST381_NCST381_V",
"NCST381_NCST381_X",
"NCST381_NCST381_Z",
"NDE1503_NDE1503_V",
"NDIM381_NDIM381_V",
"NDIM381_NDIM381_W",
"NDIM381_NDIM381_X",
"NDIM381_NDIM381_Y",
"NDOD381_NDOD381_U",
"NDOD381_NDOD381_W",
"NDOD381_NDOD381_X",
"NEHV381_NEHV381_W",
"NEHV381_NEHV381_X",
"NEHV381_NEHV381_Y",
"NEHV381_NEHV381_Z",
"NENS381_NENS381_T",
"NENS381_NENS381_U",
"NENS381_NENS381_W",
"NHGL381_NHGL381_X",
"NHGL381_NHGL381_Y",
"NHGL381_NHGL381_Z",
"NHSW222_NHSW222_X",
"NHSW222_NHSW222_Y",
"NHSW222_NHSW222_Z",
"NKIJ381_NKIJ381_V",
"NKIJ381_NKIJ381_Z",
"NMBT381_NMBT381_U",
"NMBT381_NMBT381_V",
"NMBT381_NMBT381_W",
"NMBT381_NMBT381_X",
"NOZN381_NOZN381_W",
"NOZN381_NOZN381_X",
"NOZN381_NOZN381_Y",
"NWL3801_NWL3801_X",
"NWL3801_NWL3801_Y",
"NWL3801_NWL3801_Z",
"NWTR381_NWTR381_M",
"NWTR381_NWTR381_N",
"NWTR381_NWTR381_O"
],
"conjunction": "and",
"level": 2,
"userFriendlyValue": [
"NBSL381_NBSL381_U",
"NBSL381_NBSL381_V",
"NBWK381_NBWK381_U",
"NBWK381_NBWK381_W",
"NBWK381_NBWK381_Y",
"NCST381_NCST381_V",
"NCST381_NCST381_X",
"NCST381_NCST381_Z",
"NDE1503_NDE1503_V",
"NDIM381_NDIM381_V",
"NDIM381_NDIM381_W",
"NDIM381_NDIM381_X",
"NDIM381_NDIM381_Y",
"NDOD381_NDOD381_U",
"NDOD381_NDOD381_W",
"NDOD381_NDOD381_X",
"NEHV381_NEHV381_W",
"NEHV381_NEHV381_X",
"NEHV381_NEHV381_Y",
"NEHV381_NEHV381_Z",
"NENS381_NENS381_T",
"NENS381_NENS381_U",
"NENS381_NENS381_W",
"NHGL381_NHGL381_X",
"NHGL381_NHGL381_Y",
"NHGL381_NHGL381_Z",
"NHSW222_NHSW222_X",
"NHSW222_NHSW222_Y",
"NHSW222_NHSW222_Z",
"NKIJ381_NKIJ381_V",
"NKIJ381_NKIJ381_Z",
"NMBT381_NMBT381_U",
"NMBT381_NMBT381_V",
"NMBT381_NMBT381_W",
"NMBT381_NMBT381_X",
"NOZN381_NOZN381_W",
"NOZN381_NOZN381_X",
"NOZN381_NOZN381_Y",
"NWL3801_NWL3801_X",
"NWL3801_NWL3801_Y",
"NWL3801_NWL3801_Z",
"NWTR381_NWTR381_M",
"NWTR381_NWTR381_N",
"NWTR381_NWTR381_O"
]
}
]
Ich mag würde, den Inhalt von einigen der „Wert“ Schlüssel mit Daten aus einer MySQL-Abfrage ersetzen, die den vorherigen Wert als Argument verwendet.
Zum Beispiel in dem Fall dieses Objekt
{
"item": {
"name": "elementName",
"type": "table",
"displayName": "Element name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "in",
"value": [
"NEHVN_3_NOIRSC3_1",
"NGNHU_5_NGNHU_5_1",
"NMVL381_NMDC381_1",
"XGR_MA1_NMDC381_1"
],
"conjunction": "or",
"level": 2,
"userFriendlyValue": [
"NEHVN_3_NOIRSC3_1",
"NGNHU_5_NGNHU_5_1",
"NMVL381_NMDC381_1",
"XGR_MA1_NMDC381_1"
]
},
wenn die mysql query
183213,
834924,
986312,
987312
das Objekt
{
"item": {
"name": "elementName",
"type": "table",
"displayName": "Element name",
"operators": [
"in",
"not in",
"=",
"<>",
"like"
],
"values": []
},
"operator": "in",
"value": [
183213,
834924,
986312,
987312
],
"conjunction": "or",
"level": 2,
"userFriendlyValue": [
"NEHVN_3_NOIRSC3_1",
"NGNHU_5_NGNHU_5_1",
"NMVL381_NMDC381_1",
"XGR_MA1_NMDC381_1"
]
},
würde zurückgekehrt Ich hatte geplant, über die Schleife erstes Array mit jqs ". [0]" ". [1]" und verkettete resultierende json in der Schleife.
Gibt es einen schlaueren oder allgemein besseren Weg? Ich kann sehen, dass jq Schleifen hat, aber ich konnte sie nicht verwenden.
Post das gewünschte Ergebnis – RomanPerekhrest
Es ist da. Danke, dass du darauf hingewiesen hast. – Gryffus