Question: I am trying to parse a JSON file that use single quotes to get a valid Elasticsearch bulk load JSON format.

What I want to do is replace single quotes with double quotes but I don't want to do it if the single quotes are enclosed by single quotes.

Example:

```
{
    'title': 'Charlie's Angels',
    'review': 'I don't really like this 'movie''
}

```

Should be converted to:

```
{
    "title": "Charlie's Angels",
    "review": "I don't really like this 'movie'"
}

```

So I think I need is a sort of regex that match single all single quotes but those enclosed by single quotes.
Unfortunately I've tried various workarounds but I don't seem to be able to get it right... 

Any suggestions?

Answer: 
If the input really looks like this, and of course I am making some assumptions, I would use `sed` to repair it (I will not call it a conversion):

```
sed "s/^\([ \t]*\)'/\1\"/; s/'\(:[ \t]*\)'/\"\1\"/; s/'[ \t]*$/\"/" < data
{
    "title": "Charlie's Angels"
    "review": "I don't really like this 'movie'"
}

```
The best I was able to do with regex is this:

```
(:?'(.*?)'([:,\s]))

```

It matches only quotes that are followed by a white space, colons or commas, what is ok in your testcase, but may not work always. For more testing, I would need more test data.

You can use this regex like this:

```
data = re.sub("(:?'(.*?)'([:\s]))", lambda m:f'"{m.groups()[1]}"{m.groups()[2]}',data)

```