Skip to content

Conversation

@phron3sis
Copy link

add overloads to make setting values in json 1 line of code instead of 3

@Torwent
Copy link
Collaborator

Torwent commented Jan 19, 2026

I've done something like this on 1.4 and with time, I consider it was a mistake. Reason being that JSON in Simba is a little bit awkward and complicated to use and people would learn my wrapper around it but then they would be completely stuck when they wanted to do more advanced JSON things and it wouldn't support it, like nested JSON items.

In 1.4 I don't quite remember what it was that ended up preventing me from doing so, but I think we can do it on 2.0 and I think it would probably be best if we built this directly on TJSONItem.

Thoughts?

@phron3sis
Copy link
Author

phron3sis commented Jan 20, 2026

Yeah that makes sense Torwent, I see your point. Building on TJSONItem directly instead:

procedure TJSONItem.Put(const key: String; value: Int64); overload;
begin
  if Self.Has(key) then
    Self.Item[key].AsInt := value
  else
    Self.AddInt(key, value);
end;

Alternative approach that avoids needing Put wrappers entirely, rebuild from scratch each save instead of mutating existing JSON.

  Fjson := new TJSONObject;

  Fjson.AddFloat('S', Self.State.S);

I'm not sure what is best. My initial idea wasn't well thought out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants