I have a JavaScript file containing many object literals:

```
// lots of irrelevant code
oneParticularFunction({
    key1: "string value",
    key2: 12345,
    key3: "strings which may contain ({ arbitrary characters })"
});
// more irrelevant code

```

I need to write some Python code to extract these literals.

My first attempt was a regular expression `oneParticularFunction\(\{(.*?)\}\);`. But this fails if the literal contains a "})".

Since I know the objects will be valid JSON (matched quotes, braces, etc) in a valid JavaScript file, is there a more elegant way to extract them?

(In other words, the difficulty is removing all the other JavaScript code I don't care about.)

EDIT: In the end, I used a regular expression for any objects which don't contain sub-objects...

```
oneParticularFunction\((\{([^"}]*"[^"]*"[^"}]*)*?[^"]*?\})\);

```

...and tracked open/close braces by hand for anything with nesting.