Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97327

How to edit out particular json attributes? Can regex on VSCode work?

$
0
0

I have a json file with an array of objects like this:

[
  {
    "_index": "db",
    "_type": "service",
    "_id": "1",
    "_score": 4.0,
    "_source": {
      "contentId": "1",
      "title": "Sample 1",
      "tokenizer": "whitespace",
      "keyword": ["sample1", "service"],
      "desp": "Desc this Service",
      "contentType": "service",
      "url": null,
      "contentCategory": "Services",
      "contentSubCategory": null,
      "assignmentProfile": null,
      "employeeId": null,
      "assignmentProfileId": null,
      "managedRuleId": null,
      "contentAcademy": null,
      "imageUrl": null,
      "metaData": [
        "sample1",
        "services"
      ]
    }
  },
  {
    "_index": "db",
    "_type": "service",
    "_id": "2",
    "_score": 7.0,
    "_source": {
      "contentId": "2",
      "title": "Sample 2",
      "tokenizer": "whitespace",
      "keyword": ["sample2", "service"],
      "desp": "Desc this Service",
      "contentType": "service",
      "url": null,
      "contentCategory": "Services",
      "contentSubCategory": null,
      "assignmentProfile": null,
      "employeeId": null,
      "assignmentProfileId": null,
      "managedRuleId": null,
      "contentAcademy": null,
      "imageUrl": null,
      "metaData": [
        "sample2",
        "services"
      ]
    }
  }
]

I need to remove certain fields in this. All the fields beginning with the _ and metadata field. It needs to end up like this:

[
  {
    "contentId": "1",
    "title": "Sample 1",
    "tokenizer": "whitespace",
    "keyword": ["sample1", "service"],
    "desp": "Desc this Service",
    "contentType": "service",
    "url": null,
    "contentCategory": "Services",
    "contentSubCategory": null,
    "assignmentProfile": null,
    "employeeId": null,
    "assignmentProfileId": null,
    "managedRuleId": null,
    "contentAcademy": null,
    "imageUrl": null
  },
  {
    "contentId": "2",
    "title": "Sample 2",
    "tokenizer": "whitespace",
    "keyword": ["sample2", "service"],
    "desp": "Desc this Service",
    "contentType": "service",
    "url": null,
    "contentCategory": "Services",
    "contentSubCategory": null,
    "assignmentProfile": null,
    "employeeId": null,
    "assignmentProfileId": null,
    "managedRuleId": null,
    "contentAcademy": null,
    "imageUrl": null
  }
]

I want to write a regex expression on VSCode to do the above. I wrote the following:

"metaData": \[\r\n (.+) ],

to replace the metaData attribute with a empty string. But that doesn't match.

The array size is 100+ and thus is there a expression to match this with?


Viewing all articles
Browse latest Browse all 97327

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>