Downloaded JSON solutions are not understandable

TL;DR - Need help parsing the downloaded solution to understandble js

So i’ve finished all the basic js and es6, wanted to do a review annnnnd it’s gone,
I can’t view my old solutions (they don’t appear on fcc, only in green, so i downloaded them), the downloaded file is in json annd since it’s json i reallly cant understand anything written…
I just want to review my solutions… any help guys?

1 Like

If you’re talking the file that you can download from your settings page, I believe that it only contains the solutions to your project challenges. The lesson challenges give you the opportunity to download your solution when you submit them, but they aren’t saved by FCC.

Exactly , i used it as an alternative to not being able to see my old solutions.
Now i have them downloaded, but i’m unable to see what’s inside due to the json format…

This is what i need help with,
I need to be able to see my old solutions, could you help me out Ariel?

You aren’t listening. The only old solutions that would be there are the projects at the end of sections. It does not include solutions that are not linked to elsewhere on the settings page.

Yes, i know but i’m not talking about the project solutions saved on the page of fcc…
I’m talking about parsing the json file to js so i could Read them

like this is what i have:

{"index.js":"// Setup\nvar testObj = {\n  \"an entree\": \"hamburger\",\n  \"my side\": \"veggies\",\n  \"the drink\": \"water\"\n};\n\n// Only change code below this line\n\nvar entreeValue = testObj[\"an entree\"];   // Change this line\nvar drinkValue = testObj[\"the drink\"];    // Change this line"}

I want to read it as normal js…

If the JSON file does include the challenges you want, then you need to find the key for the challenge you’re interested in. The value will be the solution code in the form of a string. When you parse the string all of the escaped characters will be presented as their parsed counterparts.

nvm… pretty pointless offering to save an unreadable file no?
Thanks for the help.
Guess that save solution is pretty pointless.

Guess i have to go clean ctrl shift l all that regex out manually…
all i wanted was some help…

And regex is what you need.

  1. Eliminate ‘n’ which are preceded by '' aka ‘\n’.
  2. Eliminate all white spaces except one on each end of the word.
  3. That

and its ending at the back you can eliminate by hand …
Just slice these off and return string with out them.

2 Likes

Thanks man, i’m glad someone understood what i meant.

1 Like

They aren’t unreadable. They are readable by a computer. Rather than manually removing all the escaped characters, you just need to parse the string.

And that is what i asked helped with :slight_smile:

Again, i’m having difficulties parsing the string could you show me the code you used?

Thank you again

I just pasted the string in the Dev tools console. Anything that parses a string will work.

Hi, I’m not sure why the answers are being provided in this format. I found it pretty confusing and not a good user experience. I wound up creating a solutions.html file with code that parses the downloaded solution:

<!-- HTML boilerplate -->   
<body>
<script>
  var obj = // Paste your solution text here
  console.log(obj[Object.keys(obj)[0]]);
</script>
</body>

If you open the page with a browser it will log the solution in the console in a readable format. Even this isn’t terribly helpful though, since the console doesn’t highlight syntax or allow easy editing. The best approach is probably to bypass the download button altogether and just copy and paste your answer into your favorite IDE and save from there. Here is a pen (make sure to open console to view solution).

4 Likes

Thanks for the answer :slight_smile:

Can you elaborate on why JSON files are saved in this format? When I open a javascript or other file with code in it, new lines don’t display as \n

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings

I understand what escape characters are and why they’re used - but why are they used inside JSON files, and not HTML files (for example) ?

Escape characters are necessary for formatting strings in JavaScript. JSON is JavaScript Object Notation. In order for the code to show up in the editor window broken into lines with indentation, the escape characters need to be there. Otherwise it would all be one long line.

Hi dude, I was dealing with this task for a friend, and as I was typing up my notice of creating a tool for this, your topic popped up. Here ya go:

10 Likes