'How to move JSON fields in mass effectively?

I have a JSON like this:

{
    "array1": [
      {
        "data": {
          "id": "1",
          "name": "foo",
        },
        "classes": "class1" 
      },
      {
        "data": {
          "id": "2",
          "name": "bar",
        },
        "classes": "class2"
       ...
      }
} 

I want to move all the classes into data object. Using https://jsoneditoronline.org I can only do that for each object individually. I guess I can write a script to do this, but is there a built tool for this?



Solution 1:[1]

It seems that regex is the quickest way to do this. Here is how I do:

  • Search: ("data".*?)(}.*?)(,"classes":.*?)}
  • Replace: $1$3$2}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ooker