Open jeroenbrussich opened 3 years ago
Hey there,
Thanks for the in-depth notes. The JSON files aren't really designed to be user-editable. It's been a long time since I touched the code that deals with these but it's mostly in this file: https://github.com/cynicaloptimist/improved-initiative/blob/development/client/Utility/LegacySynchronousLocalStore.ts
The JSON files are produced by JSON.stringify, so it would be strange if they were incorrectly formatted. See this method: https://github.com/cynicaloptimist/improved-initiative/blob/development/client/Utility/LegacySynchronousLocalStore.ts#L92
The one-liners you're referring to are valid JSON. Each of them is an index of the keys of the items in the file. This is required for localstorage interoperability.
I have no plans to make these files more user-editable, but I am currently, slowly, working on a Library Manager UI that will include things like bulk export (so you can pick and choose what to include in a JSON file.)
Hope that helps!
Hi there @cynicaloptimist
Thank you for your response! I understand that you don't want to touch working code :) If it ain't broken, don't fix it
Can I just add 2 small remarks before you go and close this "issue"?
\"
you can see on each line..I fiddled around in python and got these results.
\"
\"
for "
, I can parse that line into a json-tree [= json.dumps( var, indent=4)]. Pay attention to the double quotes without the backslash.\"
is back againSo while you are correct I was a little bit harsh in my wording to call your data invalid JSON, it is however strangely formatted, as if the data was twice exported to json And I don't think that is because of json.stringify() because the testpage returns (what I call) valid json
However, it is kind of strange that my "valid" json is not accepted by the importer, and the "invalid" json is, but only for characters, not for creatures . So maybe, just maybe, there is something going on there? I have too little knowledge of node.js to help you look into it. But maybe it is worth looking into in the far future?
For the time being, you may close this issue as being resolved :D
trying using JSON.parse
on the data
oneliner
in that case is a valid JSON string, which includes escaped double-quotes \"
when printed as a string value. json.dumps
takes a dict
(or other JSON compatible type) and encodes it. So your red highlighted code is in fact double-encoded.
The valid Python would look like:
import json, pprint
oneliner = "{\"oneliner\": true}" # String with JSON encoded data
data = json.loads(oneliner) # Parse the string into Python types
pprint.pprint(data) # Print the Python data structure nicely
nice = json.dumps(data, indent=4) # Dump the Python data into a nice human readable JSON encoded string
print(nice) # Print the string containing nicely formatted data
You can try doing the following:
const obj = {\"foo\" : 3}
const str = obj.toString();
str.replace("\"", '"');
obj = JSON.parse(str)
we should really try to come up with some guides about JSON-files for Improved Initiative.
I am trying to understand how to create said JsonFiles but I can't seem to find any consistency in them. Allow me to explain.
upload
I found (this file) online with working data for Improved Initiative. If you would open the file, you would see about 20 "oneliners" with incorrectly formatted json data. Paste the content in https://jsoneditoronline.org/ if you would like to see what I mean.
download
Anyway, the file works for II. So I import the data and download it immediately. That gives me 02 - download initial upload.txt. Open this file and you will have incorrectly formatted _"ImprovedInitiative.PersistentCharacters"-oneliners and correctly JSON-formatted "Creatures"-blocks. Again, paste the content in https://jsoneditoronline.org and scroll all they way down to see what I mean.
about creatures
When I strip one creature from the first file, the one with the incorrectly formatted oneliner, I can upload that data if the array
"ImprovedInitiative.Creatures": "[\"j1van1rm\"]"
is present.When I strip one creature from the second file, the one I downloaded with some correctly formatted JSON data, I can successfully upload correctly formatted json-data. The "array" does not even have to be present, I just have to start my data with
"Creatures.
Just for trying, I combined the array with the JSON-data, but that fails..
about characters
When I strip one creature from the first file, the one with the incorrectly formatted oneliner, I can upload that character if the array
"ImprovedInitiative.PersistentCharacters": "[\"mcerm30e\"]"
is present.HOWEVER, when I convert that file to valid JSON data , and omit said array, nothing happens. I tested with both
"PersistentCharacters."
and"Characters.
but my Characters-tab remains empty when I serve this file.So, my big question is: