Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I want to change large text file to json format can we do it? I have tried text file to convert to xls and xls file to csv and agin that csv to json format but in that i am facing some proble that is some attribute changes to null .So is there any shortcut to change the text file to json file with all data.If any please kindly response as soon as possible.
Posted

I think you need to

1) explain what you mean by JSON format and or check the definition.
2) explain what you'll be doing with the JSON data that 'represents' a file

you could, for example, do something like this :-

"MyFileStringArray" : ["File Line 1", "File Line 2"]


but that really depends what you want to DO with the JSON data - you could parse/split each line into some sub-lines/segments etc, but still, that really depends on what you need/want to do with the data

'large text file' ? .. ok - you do realise that the JSON file is going to be larger again, dont you ? - I'd argue if you just want to scan a file line by line, converting to JSON isnt the correct approach - if you're indexing the file, then you may have an array of 'index elements' where each may contain a line number from the file and index/key words

please explain more about your problem (its better if you edit/update your original question)

[edit] btw, you can apply LINQ to text files to scan/split them as well, without the need to convert them to JSON [/edit]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 27-Nov-15 1:47am    
Sure, a 5.
I a way, as a "solution" it does not make a whole lot of sense, but it makes a lot of sense to demonstrate why the question makes little sense; and this should serve as the major help, the way to appeal to some critical thinking.
—SA
The question, as formulated, makes little sense. JSON format is nothing but just format; this is the form of syntax for a JavaScript object of type 'object'. Okay, if, for example, you have some text in, say, JavaScript variable, allText, the JSON string may look as
JavaScript
{"text": allText; }

When you call JSON.stringify (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify[^]) on this object, the resulting string will give you the final result: it will be the same as the line shown in the code sample above, only allText will be replaced with its value in quotation marks. This is exactly what any other JSON processor will do.

If you want to parse some text file structure in some JSON with many properties corresponding to the elements of the input text, you need to do exactly that. But you did not say a word about the text structure, so one general way to represent the value the way I've demonstrated. (As I can see, another way is shown in Solution 1.) It hardly may make any practical sense…

—SA
 
Share this answer
 
v2
Comments
Garth J Lancaster 27-Nov-15 1:39am    
'snap' (I hope that translates ok SA) :-)

see my JSON representation of a file as JSON as an alternate to yours - an array of text file lines - doesnt make sense does it ?
Sergey Alexandrovich Kryukov 27-Nov-15 1:44am    
Yes, I already saw it and was about to up-vote it just before I saw your comment. Will do it now...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900