Search code examples
javascriptangularjsjsonparsingplaintext

AngularJS plain text parse with some simple rules


I have a .txt file with some data. I fetch the data with angular $http service. But the problem is that the data isn't in json format, but has some basic rules that I can convert it into json.

Here is an example of the data: (I write just first line, the other lines are similar to the first one)

There are 12 quotes with some data.

"123456789","some data","some data","some data","some data","some data","some data","some data","some data","some data","some data","some data"

After the above line, a new line starts with similar structure.

How can I parse it to a data-interchange format like json? See the similar question and answer.


Solution

  • You can convert it into an array of values using split.

    var text = '"123456789","some data","some data","some data","some data","some data","some data","some data","some data","some data","some data","some data"';
    
    text = text.split(',');
    console.log(text);
    

    JSFiddle