josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
814 stars 108 forks source link

OnSelect - KeySelection & ValueSelection both return KeySelection #429

Closed echan00 closed 1 month ago

echan00 commented 1 month ago

Submitting a separate issue relating to OnSelect.

I'm not that experienced, so maybe this is a false positive. But I see that KeySelection and ValueSelection are both returning the value of the Key.

Screenshot 2024-05-01 at 12 19 10 PM
josdejong commented 1 month ago

This is indeed a false positive, but I understand the confusion.

When you select either a key or a value, they both have the same path. You can distinguish them only by looking at whether the type is key or value. The value itself is not part of the path. Try for example with the Lodash function get what happens:

import { get } from 'lodash-es'

const json = {
  'string': 'Hello World'
}

console.log(get(json, ['string'])) // will print "hello World"
echan00 commented 1 month ago

Makes sense. The json is accessible so agree the key is really good enough in this case