# `Fun_GetListJson_ByKey` (function)


- **Type:** FUNCTION
- **Returns:** `longtext`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sJson` | `longtext` |
| 2 | IN | `sKey` | `varchar(100)` |
| 3 | IN | `sKeyValue` | `varchar(100)` |
| 4 | IN | `sGetKey` | `varchar(100)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTION `Fun_GetListJson_ByKey`'`._

## Narrative

**Business context:** Generic key-indexed lookup against a JSON array. Given an array `sJson` and a `(sKey, sKeyValue)` pair, finds the first element where `$.sKey = sKeyValue` and returns the value at `$.sGetKey`. Used by production-report check and OEE/work-order data-pack procs to pull a named field out of a JSON parameter list.

**What it does:** iterates the array; for each element extracts `$.sKey`, compares against `sKeyValue`; on match returns `REPLACE(JSON_EXTRACT($.sGetKey), '"', '')`. Returns `"未解析到Key"` when no element matches or input is not valid JSON.

**Invocation:** called from `Sp_Check_mftProductionReportValue`, `Sp_Check_mftProductionReportValueTest`, `Sp_OEE_ProductionReport`, `Sp_OEE_ProductionReportAll`, `Sp_WorkOrder_CalcDataPackProductStd`.
