我已经为以下输入编写了震动规范。它适用于所有元素,但对于这个事实面板->营养->列,我无法获得所需的结果。
我需要做的就是选择 json 列的第一个元素并将其带入输出中。
我的输入:
{
"upc": "9349125000405",
"brand": "BLUE DINOSAUR",
"distributor": null,
"importer": null,
"factPanel": {
"nutrition": {
"insignificantAmountStatement": null,
"labelStyle": "OLD_LABEL",
"columns": [
{
"name": "Per Serving",
"nutrients": [
{
"name": "Energy",
"valueOperator": "=",
"value": 1075.0,
"uom": "Cal",
"percentDvOperator": "=",
"percentDv": null
},
{
"name": "Protein",
"valueOperator": "=",
"value": 25.1,
"uom": "g",
"percentDvOperator": null,
"percentDv": null
}
]
},
{
"name": "PER 100 G",
"nutrients": [
{
"name": "Energy",
"valueOperator": "=",
"value": 1791.0,
"uom": "Cal",
"percentDvOperator": "=",
"percentDv": null
},
{
"name": "Protein",
"valueOperator": "=",
"value": 41.8,
"uom": "g",
"percentDvOperator": null,
"percentDv": null
}
]
}
]
}
}
}
我目前的输出:
{
"li_panel" : {
"values" : [ {
"value" : "Per Serving"
} ]
},
"li_nutrients" : {
"values" : [ {
"nutrientValue" : "1075.0 Cal 1791.0 Cal",
"nutrientName" : "Energy"
}, {
"nutrientValue" : "25.1 g 41.8 g",
"nutrientName" : "Protein"
} ]
}
}
我写的规范是这样的:
[
{
"operation": "default",
"spec": {
"*": "RemoveNullValuedData",
"categorization": {
"*": "RemoveNullValuedData"
},
"gtinFormats": {
"gtin14": "RemoveNullValuedData"
},
"sizes": {
"*": {
"netWeight": {
"*": "RemoveNullValuedData"
}
}
},
"ingredients": {
"*": "RemoveNullValuedData"
},
"factPanel": {
"*": "RemoveNullValuedData",
"nutrition": {
"*": "RemoveNullValuedData",
"serving": {
"*": "RemoveNullValuedData"
},
"columns": {
"*": {
"name": "RemoveNullValuedData",
"nutrients": {
"*": {
"*": "RemoveNullValuedData"
}
}
}
}
}
},
"specs": {
"allergensAndIntolerances": {
"*": {
"allergensAndIntolerances_tempValue": "N/A",
"allergensAndIntolerancesFree_tempValue": "N/A"
}
},
"certification": {
"*": {
"value_lc": "N/A",
"characteristic_lc": "N/A",
"segment_lc": "N/A"
},
"halal_tempValue": "N/A"
},
"fdaNutrientContentClaims": {
"*": {
"value_lc": "N/A",
"characteristic_lc": "N/A"
}
},
"foodAndBeverageEssentials": {
"*": {
"value_lc": "N/A",
"characteristic_lc": "N/A",
"segment_lc": "N/A"
}
},
"specialtyDiets": {
"*": {
"value_lc": "N/A"
}
},
"productSustainability": {
"*": {
"value_lc": "N/A",
"characteristic_lc": "N/A",
"segment_lc": "N/A"
}
},
"isolatedFibers": {
"*": {
"value_lc": "N/A",
"characteristic_lc": "N/A"
}
},
"spicesAndHerbs": {
"*": {
"value_lc": "N/A",
"characteristic_lc": "N/A",
"segment_lc": "N/A"
}
}
}
}
},
{
"operation": "modify-default-beta",
"spec": {
"~gtinFormats": "",
"~factPanel": "",
"~li_serving_size": "",
"~li_serving_size_1": "",
"~li_nutrients": ""
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=recursivelySquashNulls",
"gtinFormats": {
"gtin12?": "=concat('00',@(1,gtin12))"
},
"factPanel": {
"nutrition": {
"serving": {
"size": "=concat(@(1,size),' ',@(1,sizeUom))",
"size2": "=concat(@(1,size2),' ',@(1,sizeUom2))"
}
}
},
"sizes": {
"*": {
"netWeight": {
"value": "=concat(@(1,value),' ',@(1,uom))"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"gtin": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"productTitle": {
"RemoveNullValuedData": null,
"*": {
"@1": "li_product_title.values[].value"
}
},
"productSize": {
"RemoveNullValuedData": null,
"*": {
"@1": "product_size.values[].value"
}
},
"manufacturer": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"distributor": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"importer": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"subBrand": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"variant": {
"RemoveNullValuedData": null,
"*": {
"@1": "variant_info.values[].value"
}
},
"gtinFormats": {
"gtin12": {
"00": null,
"*": {
"@1": "gtin.values[].value"
}
},
"gtin14": {
"RemoveNullValuedData": null,
"*": {
"@1": "gtin.values[].value"
}
}
},
"sizes": {
"*": {
"netWeight": {
"value": {
"RemoveNullValuedData": null,
" ": null,
"*": {
"@1": "weight.values[].value"
}
}
}
}
},
"ingredients": {
"declaration": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"symbols": {
"*": {
"*": {
"@1": "&3.values[].value"
}
}
}
},
"factPanel": {
"nutrition": {
"insignificantAmountStatement": {
"RemoveNullValuedData": null,
"*": {
"@1": "&2.values[].value"
}
},
"serving": {
"numberPerPack": {
"RemoveNullValuedData": null,
"*": {
"@1": "li_serves_per_pack.values[].value"
}
},
"description": {
"RemoveNullValuedData": null,
"*": {
"@1": "li_serving_description.values[].value"
}
},
"size": {
"RemoveNullValuedData*": null,
"*RemoveNullValuedData": null,
" ": null,
"*": {
"@1": "li_serving_size.values[].value"
}
},
"size2": {
"RemoveNullValuedData*": null,
"*RemoveNullValuedData": null,
" ": null,
"*": {
"@1": "li_serving_size_1.values[].value"
}
}
},
"columns": {
"*": {
"name": "li_panel.values[0].value",
"nutrients": {
"*": {
"name": {
"Total Fat|Total Carbohydrate|Calories from Sat Fat Percent|Calories from Sugar Percent|Calories from Fat Percent|Sodium Per Calorie|Carbohydrate Exchange|Calories from Carbohydrate": null,
"*": {
"@(2,name)": "li_nutrients.values[&3].nutrientName",
"@(2,percentDvOperator)": {
"=": {
"@(4,percentDv)": "li_nutrients.values[&5].nutrientPercentageDailyValue"
},
"*": {
"@(4,percentDvOperator)|@(4,percentDv)": "li_nutrients.values[&5].nutrientPercentageDailyValue"
}
},
"@(2,valueOperator)": {
"=": {
"@(4,value)|@(4,uom)": "li_nutrients.values[&5].nutrientValue"
}
}
}
}
}
}
}
}
}
},
"specs": {
"allergensAndIntolerances": {
"*": {
"allergensAndIntolerances_tempValue": {
"not applicable": null,
"": null,
"*": {
"@(2,allergensAndIntolerancesFree_tempValue)": {
"\\ free": {
"@(4,value)": "li_allergensfreestatement.values[].value"
},
"* free": {
"@(4,value)": "li_allergensfreestatement.values[].value"
},
"*": {
"@(4,value)": "li_allergensandintolerances.values[].value"
}
}
}
}
}
},
"ahaStandardCertification": {
"*": {
"segment": {
"AHA Heart Check Certification": {
"@(2,value)": {
"AHA Heart Healthy Certified": {
"#American Heart Association": "li_hearthealthycertifications.values[].value"
}
}
}
}
}
},
"fdaNutrientContentClaims": {
"*": {
"characteristic_lc": {
"unsalted": null,
"*": {
"@(2,value_lc)": {
"not applicable": null,
"*": {
"@(4,value)": "li_nutritionalclaims.values[].value"
}
}
}
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"li_panel": {
"values": {
"*": {
"value": "=firstElement"
}
}
},
"li_nutrients?": {
"values": {
"*": {
"nutrientName":"=firstElement",
"nutrientValue":"=join(' ',@(1,&))",
"nutrientPercentageDailyValue": "=join(' ',@(1,&))"
}
}
},
"weight?": {
"values": {
"*": {
"value": "=trim"
}
}
},
"li_serving_size?": {
"values": {
"*": {
"value": "=trim"
}
}
},
"li_serving_size_1?": {
"values": {
"*": {
"value": "=trim"
}
}
},
"li_halal?": {
"values": {
"*": {
"value": "=firstElement",
"isDiscoveryAttribute": "=firstElement"
}
}
},
"li_grassfed?": {
"values": {
"*": {
"value": "=firstElement",
"isDiscoveryAttribute": "=firstElement"
}
}
},
"li_pectin?": {
"values": {
"*": {
"value": "=firstElement",
"isDiscoveryAttribute": "=firstElement"
}
}
},
"li_sesame?": {
"values": {
"*": {
"value": "=firstElement",
"isDiscoveryAttribute": "=firstElement"
}
}
},
"*": "=recursivelySquashNulls"
}
}
]
但我想实现如下输出:
{
"li_panel" : {
"values" : [ {
"value" : "Per Serving"
} ]
},
"li_nutrients" : {
"values" : [ {
"nutrientValue" : "1075.0 Cal",
"nutrientName" : "Energy"
}, {
"nutrientValue" : "25.1 g",
"nutrientName" : "Protein"
} ]
}
}
在 li_ Nutritions 中,我只想填充列 [0] 的值。有人可以帮我修改规格吗? 预先感谢。
PS:我已将输入和输出弄短,以便只有相关数据存在
您可以使用 shift 和随后的 modify 规范,例如
[
{ //pay attention to the renamimgs
"operation": "shift",
"spec": {
"factPanel": {
"nutrition": {
"columns": {
"0": { //because you wanna pick the first element
"name": "li_panel[0].values[0].value",
"nutrients": {
"*": {
"value|uom": "li_&2.values[&1].nutrientValue",
"name": "li_&2.values[&1].nutrientNames"
}
}
}
}
}
}
}
},
{//combine the components of the arrays, and make them key-value pairs as well
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"*": {
"*": "=join(' ',@(1,&))" // leave one char of blank between components
}
}
}
}
}
]