Using JSON parse and error detection functions by @sln,
Find/Replace is possible to pare down the objects to just two keys jobID and exec
keys and values.
For more information on how these recursive functions work and more practical
examples, see https://stackoverflow.com/a/79785886/15577665
Should be a complete and valid JSON string.
(?:(?=(?&V_Obj)){(?=(?:(?&V_KeyVal)(?&Sep_Obj))*?\s*("jobID"\s*:\s*(?&V_Value)))(?=(?:(?&V_KeyVal)(?&Sep_Obj))*?\s*("exec"\s*:\s*(?&V_Value)))(?:(?&V_KeyVal)(?&Sep_Obj))+})(?(DEFINE)(?<Sep_Ary>\s*(?:,(?!\s*[}\]])|(?=\])))(?<Sep_Obj>\s*(?:,(?!\s*[}\]])|(?=})))(?<Str>(?>"[^\\"]*(?:\\[\s\S][^\\"]*)*"))(?<Numb>(?>[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|(?:[eE][+-]?\d+)))(?<V_KeyVal>(?>\s*(?&Str)\s*:\s*(?&V_Value)\s*))(?<V_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)|(?&V_Obj)|(?&V_Ary)))(?<V_Ary>\[(?>\s*(?&V_Value)(?&Sep_Ary))*\s*\])(?<V_Obj>{(?>(?&V_KeyVal)(?&Sep_Obj))*\s*}))
Replace: { $1, $2 }
https://regex101.com/r/QI0y4i/1
Output:
{
"2597401": [
{ "jobID": "2597401", "exec": "ft.D.64" },
{ "jobID": "2597401", "exec": "cg.C.64" },
{ "jobID": "2597401", "exec": "mg.D.64" },
{ "jobID": "2597401", "exec": "lu.D.64" }
]
}
Rx Explained:
(?:
(?= (?&V_Obj) ) # Assertion : Must be a Valid JSON Object
{ # Open Obj
(?= # Lookahead: Find the 'jobID' key
(?: (?&V_KeyVal) (?&Sep_Obj) )*?
\s*
( "jobID" \s* : \s* (?&V_Value) ) # (1), capture jobID and value
)
(?= # Lookahead: Find the 'exec' key
(?: (?&V_KeyVal) (?&Sep_Obj) )*?
\s*
( "exec" \s* : \s* (?&V_Value) ) # (2), capture exec and value
)
(?: (?&V_KeyVal) (?&Sep_Obj) )+ # Get the entire Object
} # Close Obj
)
# JSON functions - NoErDet
# ---------------------------------------------
(?(DEFINE)(?<Sep_Ary>\s*(?:,(?!\s*[}\]])|(?=\])))(?<Sep_Obj>\s*(?:,(?!\s*[}\]])|(?=})))(?<Str>(?>"[^\\"]*(?:\\[\s\S][^\\"]*)*"))(?<Numb>(?>[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|(?:[eE][+-]?\d+)))(?<V_KeyVal>(?>\s*(?&Str)\s*:\s*(?&V_Value)\s*))(?<V_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)|(?&V_Obj)|(?&V_Ary)))(?<V_Ary>\[(?>\s*(?&V_Value)(?&Sep_Ary))*\s*\])(?<V_Obj>{(?>(?&V_KeyVal)(?&Sep_Obj))*\s*}))