ancient-vegetable-10556
01/07/2022, 8:24 PM#
, or swap to a YAML parser (which will read JSON with comments). Preference here?hundreds-father-404
01/07/2022, 8:26 PMancient-vegetable-10556
01/07/2022, 8:27 PMwitty-crayon-22786
01/07/2022, 8:27 PMancient-vegetable-10556
01/07/2022, 8:27 PMwitty-crayon-22786
01/07/2022, 8:27 PMancient-vegetable-10556
01/07/2022, 8:28 PMwitty-crayon-22786
01/07/2022, 8:28 PMfast-nail-55400
01/07/2022, 8:28 PMversion
key? then can read in using json.loads
, if a list then assume v1 lockfile, if an object assume v2+witty-crayon-22786
01/07/2022, 8:29 PMancient-vegetable-10556
01/07/2022, 8:29 PMhundreds-father-404
01/07/2022, 8:29 PMancient-vegetable-10556
01/07/2022, 8:29 PMfast-nail-55400
01/07/2022, 8:30 PMancient-vegetable-10556
01/07/2022, 8:31 PMfast-nail-55400
01/07/2022, 8:31 PMancient-vegetable-10556
01/07/2022, 8:32 PMhundreds-father-404
01/07/2022, 8:32 PMwitty-crayon-22786
01/07/2022, 8:33 PMancient-vegetable-10556
01/07/2022, 8:33 PMhundreds-father-404
01/07/2022, 8:34 PMWith JSON objects, the parsing will always work with one line; for TOML or JSON, you’d need to pick one format to try firstI don't follow. What do you eman?
witty-crayon-22786
01/07/2022, 8:34 PM{
"#": "This is a comment!",
"key": "value",
}
ancient-vegetable-10556
01/07/2022, 8:34 PMwitty-crayon-22786
01/07/2022, 8:35 PMancient-vegetable-10556
01/07/2022, 8:35 PMfast-nail-55400
01/07/2022, 8:35 PMNote
This module's encoders and decoders preserve input and output order by default. Order is only lost if the underlying containers are unordered.
ancient-vegetable-10556
01/07/2022, 8:36 PMjson.load
will produce a list or a dict depending on what the contents of the serialized form is (and you can process based on the type of the deserialized object); for toml we’d need to determine whether the file is toml or json somehow (e.g. trying a toml deserializer and falling back to json)witty-crayon-22786
01/07/2022, 8:40 PMancient-vegetable-10556
01/07/2022, 8:41 PMhundreds-father-404
01/07/2022, 8:41 PMfor toml we’d need to determine whether the file is toml or json somehow (e.g. trying a toml deserializer and falling back to json)But only for the sake of backwards compatibility if we want to keep the existing JSON lockfiles still working for now, right? That will go away
witty-crayon-22786
01/07/2022, 8:41 PMancient-vegetable-10556
01/07/2022, 8:43 PMwitty-crayon-22786
01/07/2022, 8:45 PMancient-vegetable-10556
01/07/2022, 8:46 PMhundreds-father-404
01/07/2022, 8:47 PMancient-vegetable-10556
01/11/2022, 10:16 PMwitty-crayon-22786
01/11/2022, 10:17 PMancient-vegetable-10556
01/11/2022, 10:19 PMwitty-crayon-22786
01/11/2022, 10:19 PMancient-vegetable-10556
01/11/2022, 10:19 PMwitty-crayon-22786
01/11/2022, 10:20 PMancient-vegetable-10556
01/11/2022, 10:21 PMwitty-crayon-22786
01/11/2022, 10:41 PMancient-vegetable-10556
01/11/2022, 10:41 PMwitty-crayon-22786
01/11/2022, 10:42 PMtry:
content = toml.loads(..)
except:
# Is either old, or corrupted: attempt to load as JSON, and assume v1
content = json.loads(..)
content['version'] = 'v1'
ancient-vegetable-10556
01/11/2022, 10:46 PM