Home > Software engineering >  Regex match JSON value on condition
Regex match JSON value on condition

Time:06-17

I have a JSON like

[{"country":"India", "State":""},{"country":"", "State":"Ohio"}]

I want to match keys which has empty values.

In this example I want to match State and country keys which has empty values.

CodePudding user response:

With capturing groups

"((?:[^"]|(?:\\"))*)":\s*""

With lookahead/behind

(?<=")(?:[^"]|(?:\\"))*(?=":\s*"")

CodePudding user response:

{"country":".*?", "State":""}

Regex match on json will work only if json is properly formatted and the key country is before State.

  • Related