Set value of key-value field

Is it possible to programmatically set the value of a key-value field? I am trying to use ->afterStateUpdated() to do something like $set('settings', '{"apiKey": "123"}'); after an item is selected from a select field. But nothing happens! The value will populate a simple text-input field, but not a key-value. Is this possible?
Was this page helpful?