Troubleshooting JSON formatting - json

I’m trying to build a large JSON file that’s a compendium for Dungeons and Dragons. I thought I had gotten my JSON formatting correct, but when I try to give it to a program that reads/navigates JSON, it’s saying that it’s not a valid JSON file. Is anyone able to take a look and maybe point me in the right direction? Here’s a shortened version of the larger file:
{"Items":{"Arrow of Slaying":{"Name":"Arrow of Slaying"},{"Detail":"very rare"},{"Magic":"Yes"},{"Roll":"6d10"},{"Description":"An arrow of slaying is a magic weapon meant to slay a particular kind of creature."},{"Type":"Arrow"},{"Weight":"0.05"}},{"Arrows":{"Name":"Arrows"},{"Description":"Ammunition: You can use a weapon that has the ammunition property to make a ranged attack only if you have ammunition to fire from the weapon. Each time you attack with the weapon, you expend one piece of ammunition. Drawing the ammunition from a quiver, case, or other container is part of the attack. At the end of the battle, you can recover half your expended ammunition by taking a minute to search the battlefield. Source: Player's Handbook p. 150"},{"Type":"Arrow"},{"Value":"0.05"},{"Weight":"0.05"}},{"Arrows +1":{"Name":"Arrows +1"},{"Detail":"uncommon"},{"Magic":"Yes"},{"Description":"You have a +1 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.05"}},{"Arrows +2":{"Name":"Arrows +2"},{"Detail":"rare"},{"Magic":"Yes"},{"Description":"You have a +2 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.05"}},{"Arrows +3":{"Name":"Arrows +3"},{"Detail":"very rare"},{"Magic":"Yes"},{"Description":"You have a +3 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.05"}},{"Blowgun Needle of Slaying":{"Name":"Blowgun Needle of Slaying"},{"Detail":"very rare"},{"Magic":"Yes"},{"Roll":"6d10"},{"Description":"A blowgun needle of slaying is a magic weapon meant to slay a particular kind of creature. Some are more focused than others; for example, there are both needles of dragon slaying and needles of blue dragon slaying. If a creature belonging to the type, race, or group associated with a needle of slaying takes damage from the needle the creature must make a DC 17 Constitution saving throw, taking an extra 6d10 piercing damage on a failed save, or half as much extra damage on a successful one. Once a needle of slaying deals its extra damage to a creature, it becomes a nonmagical blowgun needle. Source: Dungeon Master's Guide p. 152"},{"Type":"Arrow"},{"Weight":"0.02"}},{"Blowgun Needles":{"Name":"Blowgun Needles"},{"Description":"Ammunition: You can use a weapon that has the ammunition property to make a ranged attack only if you have ammunition to fire from the weapon. Each time you attack with the weapon, you expend one piece of ammunition. Drawing the ammunition from a quiver, case, or other container is part of the attack. At the end of the battle, you can recover half your expended ammunition by taking a minute to search the battlefield. Source: Player's Handbook p. 150"},{"Type":"Arrow"},{"Value":"0.02"},{"Weight":"0.02"}},{"Blowgun Needles +1":{"Name":"Blowgun Needles +1"},{"Detail":"uncommon"},{"Magic":"Yes"},{"Description":"You have a +1 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.02"}},{"Blowgun Needles +2":{"Name":"Blowgun Needles +2"},{"Detail":"rare"},{"Magic":"Yes"},{"Description":"You have a +2 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.02"}},{"Blowgun Needles +3":{"Name":"Blowgun Needles +3"},{"Detail":"very rare"},{"Magic":"Yes"},{"Description":"You have a +3 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.02"}},{"Crossbow Bolt of Slaying":{"Name":"Crossbow Bolt of Slaying"},{"Detail":"very rare"},{"Magic":"Yes"},{"Roll":"6d10"},{"Description":"A crossbow bolt of slaying is a magic weapon meant to slay a particular kind of creature. Some are more focused than others; for example, there are both bolts of dragon slaying and bolts of blue dragon slaying. If a creature belonging to the type, race, or group associated with a bolt of slaying takes damage from the bolt the creature must make a DC 17 Constitution saving throw, taking an extra 6d10 piercing damage on a failed save, or half as much extra damage on a successful one. Once a bolt of slaying deals its extra damage to a creature, it becomes a nonmagical crossbow bolt. Source: Dungeon Master's Guide p. 152"},{"Type":"Arrow"},{"Weight":"0.075"}},{"Crossbow Bolts":{"Name":"Crossbow Bolts"},{"Description":"Ammunition: You can use a weapon that has the ammunition property to make a ranged attack only if you have ammunition to fire from the weapon. Each time you attack with the weapon, you expend one piece of ammunition. Drawing the ammunition from a quiver, case, or other container is part of the attack. At the end of the battle, you can recover half your expended ammunition by taking a minute to search the battlefield. Source: Player's Handbook p. 150"},{"Type":"Arrow"},{"Value":"0.05"},{"Weight":"0.075"}},{"Crossbow Bolts +1":{"Name":"Crossbow Bolts +1"},{"Detail":"uncommon"},{"Magic":"Yes"},{"Description":"You have a +1 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.075"}},{"Crossbow Bolts +2":{"Name":"Crossbow Bolts +2"},{"Detail":"rare"},{"Magic":"Yes"},{"Description":"You have a +2 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.075"}},{"Crossbow Bolts +3":{"Name":"Crossbow Bolts +3"},{"Detail":"very rare"},{"Magic":"Yes"},{"Description":"You have a +3 bonus to attack and damage rolls made with this piece of magic ammunition. Once it hits a target, the ammunition is no longer magical. Source: Dungeon Master's Guide p. 150"},{"Type":"Arrow"},{"Weight":"0.075"}},{"Wand of Wonder":{"Name":"Wand of Wonder"},{"Detail":"rare (requires attunement by a Spellcaster)"},{"Magic":"Yes"},{"Roll":"1d6+1"},{"Description":"This wand has 7 charges."},{"Type":"Miscellaneous"},{"Weight":"1"}}}

It looks like you're having a nesting issue with your json object.
Just looking at the first bit of your json:
{
"Items": {
"Arrow of Slaying": {
"Name": "Arrow of Slaying"
},
{
"Detail": "very rare"
},
{
"Magic": "Yes"
},
{
"Roll": "6d10"
},
{
"Description": "An arrow of ..."
},
{
"Type": "Arrow"
},
{
"Weight": "0.05"
}
},
{
"Arrows": {
"Name": "Arrows"
},
{
"Description": "Ammunition: You can use a ..."
},
{
"Type": "Arrow"
},
{
"Value": "0.05"
},
{
"Weight": "0.05"
}
},
{
...
It looks like you're trying to group the details of items within their parent object, but you are actually grouping each thing as its own object, causing a nesting issue.
Here is a cleaned up version:
{
"Items": {
"Arrow of Slaying": {
"Name": "Arrow of Slaying",
"Detail": "very rare",
"Magic": "Yes",
"Roll": "6d10",
"Description": "An arrow of slaying is a magic weapon meant to slay a particular kind of creature.",
"Type": "Arrow",
"Weight": "0.05"
},
"Arrows": {
"Name": "Arrows",
"Description": "Ammunition: You can use a weapon that has the ammunition property to make a ranged attack only if you have ammunition to fire from the weapon. Each time you attack with the weapon, you expend one piece of ammunition. Drawing the ammunition from a quiver, case, or other container is part of the attack. At the end of the battle, you can recover half your expended ammunition by taking a minute to search the battlefield. Source: Player's Handbook p. 150",
"Type": "Arrow",
"Value": "0.05",
"Weight": "0.05",
},
"Continue items here": {
"Name": "Name",
"Description": "..."
}
}
}
You can tell right away that each item and its properties are properly organized. So if you need to use the type of Arrow of Slaying you can access it through: jsonVariableName['Items']['Arrow of Slaying']['Type'];
Depending on what IDE you're developing with, you might want to add a json beautify addon/ extension. I found that using a browser tool like codebeautify will just return an error if something is wrong. Instead, if you use the atom-beautify package, it will expand it and let you know where the errors are. That way you at least have something, rather than a general error that doesn't help you.
Hope this helps :)

The program is correct, that's not valid JSON. Every object, that is, {...} needs to have its properties with a name (in quotes), a colon, and then a value (that can be another object). Looking at a simple version of you JSON we have (... represent the rest of the stuff):
{
"Items": {
"Arrow of Slaying": {
"Name": "Arrow of Slaying"
},
{ "Detail": "very rare" },
...
}
}
I believe "Detail" was supposed to be a property of the same object after "Arrow of Slaying", instead of a new object. A correct JSON, in my opinion, would then be the following:
{
"Items": {
"Arrow of Slaying": {
"Name": "Arrow of Slaying",
"Detail": "very rare",
...
},
...
}
}

Related

Escaping json parsed from html using node-html-parser

I'm trying to parse the application/ld+json of a page parsed with node-html-parser I got it all working until I got this unescaped JSON issue where a \n in values is messing things up.
The small bit of JSON causing the issue (rest of JSON has been removed):
{
"name": "3. Given the balanced equation: 2H2(g) +
O2(g) --> 2H2O(l)
How many grams of H2O are formed if 9.00 mol H2(g) reacts
completely with an excess of O2(g)?
The molar mass of H2O is 18.0g/mol.
"
}
I tried using this escape function solution (simply put, str.replace(/[\n]/g, '\\n'), but it broke it.
How might I parse this string, with some values containing random new lines, and how to fix it?
Full Context (just for reference):
Source: https://www.numerade.com/ask/question/3-given-the-balanced-equation-2h2g-o2g-2h2ol-how-many-grams-of-h2o-are-formed-if-900-mol-h2g-reacts-completely-with-an-excess-of-o2g-the-molar-mass-of-h2o-is-180gmol-57997/
<script type="application/ld+json">
{
"#context": "https://schema.org",
"#type": "QAPage",
"mainEntity": {
"#type": "Question",
"name": "3. Given the balanced equation: 2H2(g) +
O2(g) --> 2H2O(l)
How many grams of H2O are formed if 9.00 mol H2(g) reacts
completely with an excess of O2(g)?
The molar mass of H2O is 18.0g/mol.
",
"text": "3. Given the balanced equation: 2H2(g) +
O2(g) --> 2H2O(l)
How many grams of H2O are formed if 9.00 mol H2(g) reacts
completely with an excess of O2(g)?
The molar mass of H2O is 18.0g/mol.
",
"answerCount": 4,
"dateCreated": "Oct. 9, 2021, 6:08 p.m.",
"author": {
"#type": "Person",
"name": "Matthew J."
},
"acceptedAnswer": {
"#type": "Answer",
"upvoteCount": 3,
"text": "In this problem, we have to find a mass of H2 that are formed if nine more of age to relax with an excess of so from balanced equation, we can see that two moles of is to Produced two moles of water, Then nine moles of H two must produce nine moles of water. So now we have most of water. We can easily find the mess MS. Of what, which is equally good number of multi multiply by the molar mass, so it is 1 62 g. So we can say that 1 62 g of H 20 are formed with nine more of age to react with Electricly with an excessive or two.",
"dateCreated": "Oct. 13, 2021, 5:12 p.m.",
"url": "https://www.numerade.com/ask/question/3-given-the-balanced-equation-2h2g-o2g-2h2ol-how-many-grams-of-h2o-are-formed-if-900-mol-h2g-reacts-completely-with-an-excess-of-o2g-the-molar-mass-of-h2o-is-180gmol-57997/",
"author": {
"#type": "Person",
"name": "Taimoor Shabbir"
}
},
"suggestedAnswer": [
{
"#type": "Answer",
"text": "So we're keeping the reaction between hydrogen all section when both off the gas, they ah ah, in the container. So a spark, An initial initiated reaction to your form. Water. So here we have soup on serial fees there from five graham off hydrogen and also syrup on Syria. When a five month off oxygen, what would be the mass of water being produce? So first of all, we have to Bannister can call the Ashram. Um, as you can see, that we have to Ah, hydrogen on the on the left. So we have it for two under, right? And then we have four hydrogen. So on the love we were just put put to you from the hydrogen and then the whole reaction Spartans. Okay, so the next step before we do anything is convert anything. That is not your number. Motion on verbal. So we're still points several feet. That's 75 year bites You where? Sierra 750.1 it if there were 18 eight. Uh, both. Okay, so, um, we have the lumber. I'm also had to found the limiting We agent we had found an emitting region, and then we can just a limbo move in different dimension. We agent to find out the mass off our water. Okay, so then they assume we Ah, I would pick all hydrogen. Assume I have. Ah, them. You have that much hydrogen, You know that? The footy we act so we will. How many oxygen do I need? The militia is 2 to 1 for Ah, hydrogen oxygen. So I just take ah, hydrogen. Um, the more motive I bite you, so I will have Ah, sirrah, point. Seriously. 09 for most of oxygen required to fully re at with. Ah, Hodgins. Okay, So this is the require amounts over here, over here. And there's the actual mouth, so you can see that. Actually, we have a lot off oxygen. So the excess we aging essentially, it's all sitting over here. All right, so let's stab is we're going to Ah, use hydrogen number mostly found that ward number almost again because we have enough also, June. But, uh, I know that the food that we have with all the hydrogen Okay, so the limbo move off water, it would be ah, we can find the from the motorway show and also find from the number of most of hydrogen. So the mother wisher is 2 to 2. Essential is 1 to 1. So it's essentially the same as the number most over here for water. So sue syrup on Syria 18 Ah, for out to the moment of water. Okay, so when we know the number more water we have vowed a mass, we just the more plight, Um, the mass off the mill a massive waters with 18 by the limbo Moe's so so far 018 times 18 And that which you have several 180.338 gram for water. Okay, so, uh, we've already filed the mass of water. We know that excess we agent sausage in. So how about the oxygen? We meaning? All right. So we have that much of all sojourn. 0.185 and then we know that you know that hopefully we have imagined they will consume syrup on sale soon. 94 So we just took our agent Noh Ah, concentration off our region. Know them. Don't move for oxygen. Subtract Ah ah ah! Mom required if we were rehab before their hydrogen and that we should be able to find out is because the syrup on cereal night one most we meaning for oxygen remaining this we meaning. And then we can further, um, convert that back to our master. You corresponding to Syria 0.219 Grandma Oxygen. We may you know, we asked your picture.",
"dateCreated": "Aug. 11, 2021, 12:50 a.m.",
"upvoteCount": 3,
"url": "https://www.numerade.com/questions/a-mixture-of-00375-g-of-hydrogen-and-00185-mol-oxygen-in-a-closed-container-is-sparked-to-initiate-a/",
"author": {
"#type": "Person",
"name": "Stephen Ho"
}
},
{
"#type": "Answer",
"text": "The reaction equation in this question is based on the same reaction equation that we had in the previous question. Now, during this reaction, five moles of hydrogen gas reacts with 0.15 moles of oxygen gas in order to produce a certain amount of water. We need to identify the limiting reactant here and also calculate the number of moles of water that can form during this reaction. For this purpose. We will look at two different situations in order to identify the limiting reactant first and that is, um firstly, we will look at the number of moles of water that can be produced If we start off with five moles of hydrogen gas, and secondly, we will look at the number of moles of water that can be produced when starting off with a 0.15 zero moles of oxygen gas. We will then compare these two situations in order to identify the limiting reactant. So, firstly, In order to determine the number of moles of water that can form when starting off with five miles of hydrogen gas, we need to work with the more ratio of water to hydrogen gas. So for this purpose, we will have a look at the stock geometric coefficients here. For water, it is 24 hydrogen gas, it is too, so that more ratio of water um over hydrogen guests is to over two. We can therefore say That the number of moles of water that can form in this case will be one times the number of moles of hydrogen gas, And this is equal to one times five moles, Which is just equal to five moles. Right now, let's look at the second situation where we start off with 0.15 moles of oxygen. Once again, we need to make use of the mole ratio. So in this case it will be to over one. So the number of moles of water with a number of moles of oxygen will be to over one. This means that the number of moles of water that can form in this case is two times the number of moles off oxygen gas. So this is two times uh 1.50 moles, and this is equal to three moles. Right? So in the first situation, when we started off with five miles off hydrogen gas, We were able to form five moles of water. But in the case of oxygen, we start off with oxygen Um and specifically 1.50 moles of oxygen. Then we can only end up with 3.00 moles of water, which is the least amount produced in the two situations. So because we can only produce a maximum A number of moles of three moles of water, this indicates that oxygen is the limiting reactant here. Oxygen is the limiting reactant. And if we start off with 0.150 miles of oxygen, Then we can produce three moles of water. Right? So to recap in this reaction, we had to identify the limiting reactant first. For this purpose, we compare the number of moles of water that um could form, starting off with the different number of moles off either. Um First of all, we looked at hydrogen gas and then on the other hand, the number of moles of oxygen gas. So in this way we realized that the limiting reactant is oxygen gas because it can only form three moles of water compared to the five mills that can be formed when we start off with the hydrogen gas, is the reactant. Now, if we start off with oxygen 0.15 moles of oxygen gas, then um three miles of water was formed in the end",
"dateCreated": "Aug. 11, 2021, 12:50 a.m.",
"upvoteCount": 3,
"url": "https://www.numerade.com/questions/if-500-mathrmmol-of-hydrogen-gas-and-150-mathrmmol-of-oxygen-gas-react-what-is-the-limiting-reactant/",
"author": {
"#type": "Person",
"name": "Marietjie Lutz"
}
},
{
"#type": "Answer",
"text": "for this problem, we're gonna be working on understanding limiting reactions and using them to solve for products, were given that we have this chemical equation four, NH three plus 502 yields four N O plus six H 20 Were given that we have 2.35 moles of NH three and 2.75 moles of 02 To work with, we need to understand which of these reactions is the limiting reactant and then use that to figure out how much water we're will be produced. It's important to figure out which of these is the limiting reactant, because this reaction will only go so far as that reaction allows. So, to figure out which one is the limiting reactant, we can choose to use either the NH three or the 02 It doesn't matter. I'm gonna go with the NH three. So I'm going to lay out what I have, I have 2.35 moles of NH three. Next thing I'm gonna do is I'm going to look at our ratio by looking at the coefficients in our balanced equation and see that for every four moles of NH three, we're going to also use five moles of 02 So the way to work this out is I'm going to multiply 2.35 by five and then whatever I get from that, I will then divide by four. And when I do that I get 2.94 malls of 02 because our moles of NH three will cancel out. So then I'm going to go look at how much 02 were given. 2.75 Well, that is that is less than 2.94 So, what this means is that we do not have enough 02 to fully react with the NH three that were given. So that means that are limiting reactant is 02 The next thing we're gonna do is we're going to use that limiting reactant to solve for another ratio like this to find out how much water is going to be produced. So we have 2.75 moles of 02 to work with. We're going to set up our ratio again for every five moles of 02 we can create six moles of H 20 I'm going to multiply 2.75 by six and then divide that answer by five to get 3.30 moles of H 20 and that is how much water we can produce.",
"dateCreated": "Aug. 11, 2021, 12:50 a.m.",
"upvoteCount": 3,
"url": "https://www.numerade.com/questions/in-the-following-reaction-235-mathrmmol-of-mathrmnh_3-reacts-with-275-mathrmmol-of-mathrmo_2-how-man/",
"author": {
"#type": "Person",
"name": "Shaelyn Deal"
}
},
{
"#type": "Answer",
"text": "in this question, Methane gas reacts with oxygen in order to form carbon dioxide and water. So this is a combustion reaction and we start off with one mole of methane gas and five moles of oxygen gas. Now we need to determine the limiting reactant here so that we can determine the number of moles of water that perform in the end. In order to determine that limiting reactant, we will compare the number of moles of water that can be formed Firstly, if we start off with one mole of the fungus and secondly, then if we start off with five miles off oxygen gas. So when we compare these two situations, we will be able to identify the limiting reactive. Now, in order to determine the number of malls Can be formed from one mole of methane gas, we make use of the mole ratio. So we know that geometric coefficient of water six and has a documentary coefficient of two. So the mole ratio of water to six, the kids. Therefore the number of moles of water can be formed in this case 6/2", 3 times the number of Malzahn. Yes. Right. And we know we saw it off with um five starting with one mole of methane gas. And therefore this number of northern waters will be $3.1 which is equal to three months. Right. So let's have a look at the second situation where we choose to start off with the oxygen as our reacted. No, once again, you wanted to To calculate the number of moles of water that can be produced. We need to make use of the mole ratio more racial. In this case of water to oxygen is 6-7. So the number of moles of water Over the number of number of moles of oxygen will be 6, 7. So the number of moles of water that can be 46 or seven times oxygen. So it's 6/7 times. We started off with five levels of oxygen, six of the seven times 5 And that is equal to round off to two decimal places. 4.29. Uh huh. So now I need to compare the number of moles that can be formed in these two different situations to firstly, when I started off with one more of methane gas, The reaction um we're able to produce three moles of water. But if I started off with five months of oxygen gas, We actually were able to produce, 4.29 mi of water. So therefore the maximum number of moles that can be produced in this case. Yes, three. And that is from using um it's in gas, which is the limiting reactant. So we started off with a balanced equation and we had to identify the limiting reactant in this case by and we did that by comparing the number of moles of water that could form by starting off in the first place with one more of anything goes. In the second place, five moles of oxygen within. Saw that um The methane gas could not produce more than three miles. Um whereas the oxygen case of the oxygen, Um the reaction produced 4.29 moles. So because we could only produce three moles by using one move methane gas, this is the maximum number of moles that could be produced in this reaction. And therefore we also know that um the limiting reacting to here is a same gas.",
"dateCreated": "Aug. 11, 2021, 12:50 a.m.",
"upvoteCount": 3,
"url": "https://www.numerade.com/questions/if-100-mathrmmol-of-ethane-gas-and-500-mathrmmol-of-oxygen-gas-react-what-is-the-limiting-reactant-a/",
"author": {
"#type": "Person",
"name": "Marietjie Lutz"
}
}
]
}
}
</script>
Basically, I was trying to read broken JSON, as Felix mentioned JSON cannot contain literal line breaks.
Solution: use https://www.npmjs.com/package/jsonrepair module. It detected the bad lines and fixed them, this is likely what google does (some sort of JSON repair).
PS: I tried https://www.npmjs.com/package/json-fixer without success

How to prevent the eligibility trace in SARSA with lambda = 1 from exploding for state-action pairs that are visited a huge number of times?

I was testing SARSA with lambda = 1 with Windy Grid World and if the exploration causes the same state-action pair to be visited many times before reaching the goal, the eligibility trace gets incremented each time without any decay, therefore it explodes and causes everything to overflow.
How can this be avoided?
If I've understood correctly your question, the problem is that the trace for a given state gets incremented too much. In this case, a potential solution is to use replacing traces instead of the classic incremental traces.
The idea in replacing traces is to reset the trace to a value (typically 1) each time the state is visited. The following figure illustrates the main difference between both kinds of traces:
You can find more information in the classical Sutton & Barto book Reinforcement Learning: An Introduction, especifically in Section 7.8.

Error message when converting json into csv file

I saw several posts about converting json into csv in R, but I have
this error:
Error in fromJSON(file = "C:/users/emily/destop/data.json") : argument "txt" is missing, with no default) after running following code.
mydf <- fromJSON(file= "C:/users/emily/destop/data.json")
I downloaded jsonlite package.
It seems that the command doesn't read the json data correctly or cannot convert it into csv file.
A few sample data from data.json looks as follows:
{"reviewerID": "A3TS466QBAWB9D", "asin": "0014072149", "reviewerName": "Silver Pencil", "helpful": [0, 0], "reviewText": "If you are a serious violin student on a budget, this edition has it all: Piano accompaniment, low price, urtext solo parts, and annotations by Maestro David Oistrakh where Bach's penmanship is hard to decipher. Additions (in dashes) are easily distinguishable from the original bowings. This is a delightful concerto that all intermediate level violinists should perform with a violin buddy. Get your copy, today, along with \"The Green Violin; Theory, Ear Training, and Musicianship for Violinists\" book to prepare for this concerto and for more advanced playing!", "overall": 5.0, "summary": "Perform it with a friend, today!", "unixReviewTime": 1370476800, "reviewTime": "06 6, 2013"}
{"reviewerID": "A3BUDYITWUSIS7", "asin": "0041291905", "reviewerName": "joyce gabriel cornett", "helpful": [0, 0], "reviewText": "This is and excellent edition and perfectly true to the orchestral version! It makes playing Vivaldi a joy! I uses this for a wedding and was totally satisfied with the accuracy!", "overall": 5.0, "summary": "Vivalldi's Four Seasons", "unixReviewTime": 1381708800, "reviewTime": "10 14, 2013"}
{"reviewerID": "A2HR0IL3TC4CKL", "asin": "0577088726", "reviewerName": "scarecrow \"scarecrow\"", "helpful": [0, 0], "reviewText": "this was written for Carin Levine in 2008, but not premiered until 2011 at the Musica Viva Fest in Munich. .the work's premise maybe about the arduousness, nefarious of existence, how we all \"Work\" at life, at complexity, at densities of differing lifeworlds. Ferneyhough's music might suggest that these multiple dimensions of an ontology exist in diagonals across differing spectrums of human cognition, how we come to think about an object,aisthetic shaped ones, and expressionistic ones as his music.The work has a nice classical shape,and holds the \"romantic\" at bay; a mere 7 plus minutes for Alto Flute, a neglected wind cadre member.The work has gorgeous arresting moments with a great bounty of extended timbres-pointillistic bursts\" Klangfarben Sehr Kraeftig\" that you do grow weary of; it is almost predictable now hearing these works; you know they will inhabit a dense timbral space of mega-speed lines tossed in all registers;still one listens; that gap Freud speaks about, that we know we need this at some level. . .the music slowed at times for structural rigour.. . we have a dramatic causality at play in the subject,(the work's title) the arduousness of pushing, aspiring, working toward something; pleasurable illuminating or not, How about emancipation from itself;I guess we need forget the production of surplus value herein,even with the rebellions in current urban areas today; It has no place. . . these constructions are leftovers from modernity, the \"gods\" still hover. . .\"gods\" that Ferneyhough has no power to dispel. . . . All are now commonplace for the new music literature of music.This music still sound quite stunning, marvelous and evocative today,it is simple at some level, direct, unencumbered and violent with spit-tongues,gratuitous lines, fluttertongue,percussive slap-keys,tremoli wistful glissandi harmonics, fast filigreed lines, and simply threadbare melos, an austere fragment of what was a melody. . .Claudio Arrau said someplace that the performer the musician must emanate a \"work\" while playing music, a \"struggle\", aesthetic or otherwise, Sviatoslav Richter thought this grotesque, to look at a musician playing the great music. It was ugly for him. . .You can hear Ms.Levine on youtube playing her work, she is quite convincing, you always need to impart an authority,succored in an emotive focus that the music itself has not succumbed to your own possession. You play the music, it doesn't \"play\" you. . . I'd hope though that music with this arduous construction and structural vigour that it would in fact come to possess the performer. . .it is one of the last libidinal pleasures remaining. . .", "overall": 5.0, "summary": "arduous indeed!", "unixReviewTime": 1371168000, "reviewTime": "06 14, 2013"}
{"reviewerID": "A2DHYD72O52WS5", "asin": "0634029231", "reviewerName": "Amazon Customer \"RCC\"", "helpful": [0, 0], "reviewText": "Greg Koch is a knowledgable and charismatic host. He is seriously fun to watch. The main problem with the video is the format. The lack of on-screen tab is a serious flaw. You have to watch very carefully, have a good understanding of the minor pentatonic, and basic foundation of blues licks to even have a chance at gleening anything from this video.If you're just starting out, pick up the IN THE STYLE OF series. While this series has its limitations (incomplete songs due to copyright, no doubt), it has on screen tab and each lick is played at a reasonably slow speed. In addition, their web site has downloadable tab.However, if you can hold your own in the minor pentatonic, give this a try. It is quite a workout and you'll find yourself a better player having taken on the challenge.", "overall": 3.0, "summary": "GREAT! BUT NOT FOR BEGINNERS.", "unixReviewTime": 1119571200, "reviewTime": "06 24, 2005"}
{"reviewerID": "A1MUVHT8BONL5K", "asin": "0634029347", "reviewerName": "Amazon Customer \"clapton music fan\"", "helpful": [2, 12], "reviewText": "I bought this DVD and I'm returning it. The description and editorial review are misleading. This is NOT a Clapton video. Certainly some clips from Clapton, but generally this is a \"how to\" video. Same applies to Clapton The Early Years!", "overall": 2.0, "summary": "NOT CLAPTION MUSIC VIDEO! A Learn How To Play Guitar LIKE Clapton", "unixReviewTime": 1129334400, "reviewTime": "10 15, 2005"}
Eventually I would like to read the data correctly and convert the data into csv file.
The following should work
library(RJSONIO)
# test2.json is a sample json file
# I removed the reviewText field to keep it short
# Also tested this out with 1 row of data
D2 <- RJSONIO::fromJSON("./test2.json")
# convert the numeric vector helpful to one string
D2$helpful <- paste(D2$helpful, collapse = " ")
D2
reviewerID asin reviewerName helpful
[1,] "A3TS466QBAWB9D" "0014072149" "Silver Pencil" "0 0"
D3 <- do.call(cbind, D2)
write.csv(D3, "D3.csv")

Why is the following JSON invalid?

The following JSON is not passing validation. The validator complains at the first string value starting at "Can an officer...
It looks like the start of a valid string value for the key. What on earth could be wrong with this?
{
"DUI": {
"Can an officer arrest me because he smelled alcohol on my breath?":"<br />No, odor alone is not sufficient basis for arrest. However, odor combined with other observations such as weaving, slurred speech, and bloodshot eyes
may be enough to give an officer probable cause to arrest you for DUI.",
"Can I be convicted if I refused to take the breath test or the result was below .08?":"<br />Yes, in Washington the prosecutor can prove DUI one of two ways: 1. Blood or breath test result above .08, OR 2. Proof the person was under the
influence of or affected by liquor or drugs.
<br /><br />Additionally, if a person refused to take a test, that fact may be introduced as evidence at trial.",
"How can I be arrested if I wasn't driving my car?":"<br />A person who is in physical control of a vehicle and appears to be under the influence of drugs or alcohol may be arrested and charged under RCW
46.61.504.",
"What can I do now that I have been charged?":"<br />Contact an attorney to find out what options are available to you."
}
}
Doesn't seem to like some line breaks present in your pasted JSON:
Parse error on line 3:
...ohol on my breath?":"<br />No, odor alon
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
I pasted the JSON from your question into the validator and removed unnecessary line breaks - this works:
{
"DUI": {
"Can an officer arrest me because he smelled alcohol on my breath?": "<br />No, odor alone is not sufficient basis for arrest. However, odor combined with other observations such as weaving, slurred speech, and bloodshot eyes may be enough to give an officer probable cause to arrest you for DUI.",
"Can I be convicted if I refused to take the breath test or the result was below .08?": "<br />Yes, in Washington the prosecutor can prove DUI one of two ways: 1. Blood or breath test result above .08, OR 2. Proof the person was under the influence of or affected by liquor or drugs.<br /><br />Additionally, if a person refused to take a test, that fact may be introduced as evidence at trial.",
"How can I be arrested if I wasn't driving my car?": "<br />A person who is in physical control of a vehicle and appears to be under the influence of drugs or alcohol may be arrested and charged under RCW 46.61.504.",
"What can I do now that I have been charged?": "<br />Contact an attorney to find out what options are available to you."
}
}
http://jsonlint.com/

Most effecient way to compute a series of moves in peg solitaire

Given an arbitary peg solitaire board configuration, what is the most effecient way to compute any series of moves that results in the "end game" position.
For example, the standard starting position is:
..***..
..***..
*******
***O***
*******
..***..
..***..
And the "end game" position is:
..OOO..
..OOO..
OOOOOOO
OOO*OOO
OOOOOOO
..OOO..
..OOO..
Peg solitare is described in more detail here: Wikipedia, we are considering the "english board" variant.
I'm pretty sure that it is possible to solve any given starting board in just a few secconds on a reasonable computer, say an P4 3Ghz.
Currently this is my best strategy:
def solve:
for every possible move:
make the move.
if we haven't seen a rotation or flip of this board before:
solve()
if solved: return
undo the move.
The wikipedia article you link to already mentions that there only 3,626,632 possible board positions, so it it easy for any modern computer to do an exhaustive search of the space.
Your algorithm above is right, the trick is implementing the "haven't seen a rotation or flip of this board before", which you can do using a hash table. You probably don't need the "undo the move" line as a real implementation would pass the board state as an argument to the recursive call so you would use the stack for storing the state.
Also, it is not clear what you might mean by "efficient".
If you want to find all sequences of moves that lead to a winning stage then you need to do the exhaustive search.
If you want to find the shortest sequence then you could use a branch-and-bound algorithm to cut off some search trees early on. If you can come up with a good static heuristic then you could try A* or one of its variants.
Start from the completed state, and walk backwards in time. Each move is a hop that leaves an additional peg on the board.
At every point in time, there may be multiple unmoves you can make, so you'll be generating a tree of moves. Traverse that tree (either depth-first or breadth-) stopping any branch when it reaches the starting state or no longer has any possible moves. Output the list of paths that led to the original starting state.