Question: I very new to programming and I can't find the solution of my issue, can you give me the solution please?

I have this JSON file:

```
{
  "groups": "[{ id: 1, title: 'group 1' }, { id: 2, title: 'group 2' }]"
}

```

And I need something like this in my js (but i want import my JSON to get array like this) :

```
const groups = [{ id: 1, title: 'group 1' }, { id: 2, title: 'group 2' }]

```

I don't know how to do without using jQuery.

I already tried with this:

```
const json = require('./test.json');

```

This code returns an object: ![screen of what is returned](https://i.stack.imgur.com/ZBgT3.png)

It's almost what I want but it didn't work when I use it in my code because I don't want an object but and array like I said above.

How can achieve this?

Answer: 
The value of `groups` is not valid JSON: string values should be surrounded by double-quote marks, and so should keys. The file with valid JSON in that string would look like this:

```
{
  "groups": "[{ \"id\": 1, \"title\": \"group 1\" }, { \"id\": 2, \"title\": \"group 2\" }]"
}

```

Of course if you have control over the creation of this file, it would be better to have this value as part of the native JSON content, rather than JSON-in-a-string-inside-JSON. If that's not possible, you will need to correct the quoting in the string yourself, which can be done with a couple of Regular Expression replacements.

```
/* obj is the object in the JSON file */
var json_str = obj.groups.replace(/'/g,"\"").replace(/([a-z]+)\:/g,"\"$1\":");
var groups = JSON.parse(json_str);

```

Alternatively, although the string is not valid JSON it is a valid Javascript expression, so **if the contents of the file are trustworthy,** you can also do it with `eval:`

```
var groups = eval(obj.groups);

```
Since I didn't notice the "without jQuery" in the original question, here is a new answer:

```
var request = new XMLHttpRequest();
request.open('GET', './test.json', true);

request.onload = function() {
  if (request.status >= 200 && request.status < 400) {
    // Success!
    var data = JSON.parse(request.responseText);
  } else {
    // We reached our target server, but it returned an error

  }
};

```

It does two things:
 1. Loads the json file
 2. Parses the loaded string into a javascript object.