0

I have a really long JSON schema. Using VSCode, I need to replace the partnerName type to be string, null (it appears more than 20 times, the snippet below is just 1 appearance).

How can I search and replace the multiline for the entire partnerName entry?

From other question, I've tried using regex [\n\s]+, (.*\n)+ to be "partnerName": {(.*\n)+"type": "null"(.*\n)+}

But it's still not matching.

Search for:

"partnerName": {
          "type": "null"
        },

Replace with:

"partnerName": {
          "type": "string, null"
        },

Snippet example:

{
  "type": "object",
  "properties": {
    "node": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "frequency": {
          "type": "string"
        },
        "maxCount": {
          "type": "integer"
        },
        "points": {
          "type": "integer"
        },
        "startAt": {
          "type": "string"
        },
        "endAt": {
          "type": "string"
        },
        "partnerName": {
          "type": "null"
        },
        "action": {
          "type": "null"
        }
      },
      "required": [
        "id",
        "name",
        "description",
        "type",
        "frequency",
        "maxCount",
        "points",
        "startAt",
        "endAt",
        "partnerName",
        "action"
      ]
    }
  },
  "required": [
    "node"
  ]
},
Vina
  • 920
  • 1
  • 9
  • 12
  • You really should be parsing the json and then setting the value you want, but if you must use regex try: `(partnerName".*\n\s*"type":\s*)"null"` . – Mark Aug 07 '19 at 03:26
  • @Mark not sure what do you mean by parsing but the regex works :) thanks a lot! I'd mark it as the correct answer if you added as an answer – Vina Aug 07 '19 at 12:41
  • Are you using javascript and nodejs? – Mark Aug 07 '19 at 13:08
  • i'm ios dev and using swift daily. but for this schema, i'm writing a rest api contract test using ruby (cucumber) .. so, it's just a search & replace using text editor :) – Vina Aug 07 '19 at 15:13

1 Answers1

0

Try this regex:

(partnerName".*\n\s*"type":\s*)"null"  

and replace with:

$1"string, null"
Mark
  • 143,421
  • 24
  • 428
  • 436