Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Need a regex expression to find an integer contained in double quotes as a property value in JSON file

I imported a csv file to JSON to use it it Microsoft GRAPH’s API. I really wanna use the find/replace feature in VScode to replace the double quotes around the integer with nothing so here’s a snip of JSON

  {
"displayName": "FirewallRules/12/Action",
"description": null,
"@odata.type": "#microsoft.graph.omaSettingInteger",
"Value": "1",
"omaUri": "./Device/Vendor/MSFT/Firewall/MdmStore/FirewallRules/{firewallrulename}/Action/Type"

},

I even tries using my little knowledge of regex to get it done and had some success using this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

^(.*)"\d{1,2}(.*)"$ 

I wanna ignore "Value", ^(.?)("Value":) and only target "1"
Completely thrown together but I thought it worked, but I cant compensate for the "Value": in front of it. How can I target the Value property’s String value containing an integer with regex? Help please.

>Solution :

You can use

^(\s*"[^"]*"\s*:\s*)"(\d+)"

Replace with $1$2.

See the regex demo. Details:

  • ^ – start of a line
  • (\s*"[^"]*"\s*:\s*) – Group 1 ($1): zero or more whitespaces, ", zero or more chars other than a double quotation mark, ", a : enclosed with zero or more whitespaces
  • " – a " char
  • (\d+) – Group 2 ($2): one or more digits
  • " – a " char
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading