pyld icon indicating copy to clipboard operation
pyld copied to clipboard

compact with 'compactArrays': False always returns a graph and convert string value to list

Open sx5640 opened this issue 8 years ago • 2 comments

I running into the issue where I'm calling jsonld.compact with 'compactArrays': False, and the result I'm getting always returns a graph and convert string value to list.

The json structure I'm using is:

{
  "@context": ...,
  "key1": "abc",
  "key2": ["abc", "def"]
}

where the value of key2 can be single value or multiple values.

I can't use jsonld.compact without 'compactArrays': False when key2 has single value, it will convert it into string.

It seems that during the compact function the code will call expand first, which will expand everything into array, and 'compactArrays': False will skip all of them. skipExpansion wouldn't work either since it convert the value ofkey1 into list of chars.

I would suggest to restructure the code so that it will not do a full expand before _compact

sx5640 avatar Aug 04 '17 20:08 sx5640

Same issue here. Any update on this?

matgnt avatar Jun 28 '23 21:06 matgnt

I did look into the code a bit and I think the problem is around here:

https://github.com/digitalbazaar/pyld/blob/316fbc2c9e25b3cf718b4ee189012a64b91f17e7/lib/pyld/jsonld.py#L768

It seems to me the only decision whether to make this a graph structure or not is just the check if it is an array and I think this is not enough. I'd say it is rather the opposite and to be expected an array in most (all) cases, right? Because it is expanded before (which leads to an array...).

Unfortunately I don't have enough knowledge of jsonld in general (learning about special cases every week ;-) ) and I also don't really reliably understand all the processing happening before, I think I can not really fix this. I hope there is someone else who is able to fix this.

For now, I'll have my own code restructuring the result outside of pyld.

matgnt avatar Jul 18 '23 14:07 matgnt