I am filtering data that looks like below with json[username] for example.
data looks like:
{"albert":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"sally":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"petey":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"gilbert":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
so, for instance json[sally] brings in sally data but omits her name (the key) giving me the below:
{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}
I need to bring in/keep the name key as well. i.e. the whole line:
{"sally":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
If I hardcode it: user = "{" + username + ":"+json[username]+"}"; the object stops working: consoles as just {sally:[object Object]}. Anyway to achieve this?
json[username]works thenjsonis an object and not JSON -> What is the difference between JSON and Object Literal Notation?key: valueon its own doesn't mean anything (it's a label). Why not create an object that also includes the key, for example?