Converting list to JSON doesn't give me the correct list

So, I think when converting some 2D lists to JSON will return an empty list.

that is true...
untitled script pic (5)

which is definitely a bug since you want to keep all the data you put into it.

Yes. All data is important to save for the big project I'm making...

I'm pretty sure that isn't valid JSON. It has to be in square brackets or something.

It has to be like this:

I think it is an edge case issue as the reporter handles other cases fine

image

It does as expected with 3 items in the nested list

untitled script pic (4)

so I think it should report [["item 1"]] instead of
untitled script pic (6)

Maybe there should be some further discussion on other reported values

I, personally, think that
untitled script pic (7)
should maybe return
{"item1":{"item 2":"item 3","item 4":"item 5"}}

Link to project with examples in it
ProjectName=listToJSON

OK, but I need to find a solution asap.
Is there another JSON converter I could use?

I'm currently experimenting with writing one but not there yet

I'm also looking after a new puppy while my daughter is at work, so can only come onto the computer when she is having a nap! :slight_smile:

Would a quick piece of code work for all your current scenarios?

image

Weird, it only do that for row lists.

It is, because I did this 2 days ago and it worked, but row lists dont work now???

Seems that I've found another bug:

It's the same issue

This item will not appear is returning an empty JSON string and the 2-element list is returning its normal key/value pair result

JSON is not a good format for recursive list. Things are even worse with heuristics used by Snap
untitled script pic (24)
untitled script pic (25)

Such list should be converted as an array. Something like to "json-array" can be invented.

Yes

The problem with the first example is that
untitled script pic (9)

gives exactly what most people would want and accept

However, when going back to JSON - the first issue is that the single 1 entry is ignored (as per original reported issue) and the two element sub-list is treated as a key/value pair which is not always (as in this case) the required output.

I think (as well as fixing the issue with singletons) that there probably needs to be an enhanced version (maybe in the Lists library) that has an extra field where you can specify how to treat 2 elements lists

e.g
untitled script pic (10)
result treats two element lists as key/value pairs

and

untitled script pic (11)
result treats all lists as simple arrays

Something like this would let the user decide on how they would like the conversion doing

Also, I think that any list->JSON conversion would have to treat any alphanumeric data as strings and bracket the items with ""

I think we have to accept that the conversion from split->list->JSON may not always be fully reversible

Does this problem also occur with the csv format?

The 2 formats are completely different - csv is much simpler, so no it doesn't have the problem.

CSV works only for two-dimensional data, not lists of lists of lists.

Maybe we should have picked XML instead of JSON for deep lists, but JSON is a lot terser and therefore more human-readable. Or maybe we should have picked Lisp list notation.

But in any case I don't think we should offer JSON OF and SPLIT BY JSON functions that aren't inverses. No promises that Jens will agree. There are various ways we could fix it, basically involving various ways to represent dictionaries in Snap!.

Thank you for pointing this.

For the json problem:

  • Is the problem come the json format or the converting function using by snap ?