-1

I have a JSON file like this:

{
            "_id" : ObjectId("5627ffddce2790eea0d96ba4"),
            "type" : "FeatureCollection",
            "crs" : {
                "type" : "name",
                "properties" : {
                    "name" : "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features" : {
                "type" : "Feature",
                "properties" : {
                    "id" : 17094.0000000000000000,
                    "osm_id" : 311636347.0000000000000000,
                    "name" : "King Charles Court",
                    "type" : "apartments"
                },
                "geometry" : {
                    "type" : "MultiPolygon",
                    "coordinates" : [ 
                        [ 
                            [ 
                                [ 
                                    -123.1346724048378600, 
                                    49.2897742781884180
                                ], 
                                [ 
                                    -123.1345008272799100, 
                                    49.2898879367954520
                                ], 
                                [ 
                                    -123.1343453429760300, 
                                    49.2897882759667140
                                ], 
                                [ 
                                    -123.1345169205340000, 
                                    49.2896744497216160
                                ], 
                                [ 
                                    -123.1346724048378600, 
                                    49.2897742781884180
                                ]
                            ]
                        ]
                    ]
                }       # <-- I want to find this #
            }
        }, 
        {
            "_id" : ObjectId("5627ffddce2790eea0d96ba4"),
            "type" : "FeatureCollection",
            "crs" : {
                "type" : "name",
                "properties" : {
                    "name" : "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features" : {
                "type" : "Feature",
                "properties" : {
                    "id" : 17123.0000000000000000,
                    "osm_id" : 311859620.0000000000000000,
                    "name" : "The Burkingham",
                    "type" : "apartments"
                },
                "geometry" : {
                    "type" : "MultiPolygon",
                    "coordinates" : [ 
                        [ 
                            [ 
                                [ 
                                    -123.1352148816112600, 
                                    49.2879125736745320
                                ], 
                                [ 
                                    -123.1351233512286000, 
                                    49.2879720851870790
                                ], 
                                [ 
                                    -123.1350737303618100, 
                                    49.2879396472218050
                                ]
                            ]
                        ]
                    ]
                }     # <-- I want to find this #
            }
        }

I want to find out the Regex that will find the first closing bracket (}) after the first closing square-bracket (]) of "coordinates". So after "coordinates" : [ ...] it will match the first }. I followed some regex tutorials here but this seems to be a bit too complex for my current knowledge...

Menelaos Kotsollaris
  • 5,776
  • 9
  • 54
  • 68
  • 2
    Parsing JSON with regex is a complete pain. You can use [ruby](http://stackoverflow.com/questions/5410682/parsing-a-json-string-in-ruby), [node](http://stackoverflow.com/questions/5726729/how-to-parse-json-using-node-js), (and many other) JSON parsers to put the data you are looking for into an easier format. – Max Wofford Oct 24 '15 at 01:57
  • Agree with other comment here. Take a two back and explain why you are trying to do this. You have an easily deserializable data structure here. Why not just deserialize it? – Mike Brant Oct 24 '15 at 02:51
  • I tried to do the job via Java but I was having hard time since my files were too big. That's why I came up with the **regex** which I could run directly from `notepad++`. – Menelaos Kotsollaris Oct 24 '15 at 02:59
  • While I agree with the above comments in principle, this task doesn't seem to involve parsing. It doesn't even require keeping track of opening and closing brackets (which Notepad++ Search can do, but if you need that, you probably should be using a parser). – Alan Moore Oct 24 '15 at 03:02

1 Answers1

1

Here's the regex you described:

"coordinates"[^]]*][^}]*\}

However, in your example, the first closing brace after the first closing square bracket after "coordinates" is also the first closing brace after "coordinates", which makes the regex even simpler:

"coordinates"[^}]*\}

If you want to match only the brace, add \K right before it:

"coordinates"[^}]*\K\}

\K means "pretend the match really started here".

Alan Moore
  • 73,866
  • 12
  • 100
  • 156