Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json files in a resx are binary instead of text

Tags:

I have some test data (json files) that I am using while testing some software. It is static data and I need the tests to run locally and on build machines that I don't have to much control of. In order to get uniform access to the test data (json files) I have put them into a RESX file and that is working nicely except that I had to change the extension of the file from .json to .txt.

If I left it as .json it was added to the resx file as a "Binary" instead of "Text File". This by itself wasn't the end of the road... I simply read out the bits and converted it back to a string but when I tried to deserialize the string (after the conversion from byte[]) I got an exception for unexpected char at position 0 line 0.

The only real downside to the "txt" extension is that I loose the color coding in the IDE for a JSON file.

Is there a way to force the RESX to treat the .json extension as a "Text File"?

like image 275
Ryan Pedersen Avatar asked Mar 14 '15 19:03

Ryan Pedersen


People also ask

Is JSON binary data?

The JSON format natively doesn't support binary data. The binary data has to be escaped so that it can be placed into a string element (i.e. zero or more Unicode chars in double quotes using backslash escapes) in JSON. An obvious method to escape binary data is to use Base64.

What is Resx format?

resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.

What does RESX file contains?

resx file contains a standard header, which describes the format of the resource entries and specifies the versioning information for the XML that is used to parse the data. The resource file data follows the XML header. Each data item consists of a name/value pair that is contained in a data tag.

What does Resx mean?

resx) files are a monolingual file format used in Microsoft . Net Applications. The . resx resource file format consists of XML entries, which specify objects and strings inside XML tags.


2 Answers

Maybe it's too late, but there is a very simple method to achieve what you want. Just select the desired file in the resources window, hit F4 or go to the Properties and select proper FileType there. It has two options: binary and text.

enter image description here

like image 67
Axm Avatar answered Oct 15 '22 08:10

Axm


A colleague of mine just encountered a similar issue with a .cshtml file. The actual content of the file didn't seem to matter when we renamed the file to have an extension that was known to work caused it to add as text.

Also, Axm's suggestion worked to fix it, but we initially missed it because you can't right-click on the resource and select properties.

like image 44
drs9222 Avatar answered Oct 15 '22 09:10

drs9222