Skip to content

JSON keys are incompatible with Web IDL dictionaries #554

@annevk

Description

@annevk

Per https://w3ctag.github.io/design-principles/#casing-rules an IDL dictionary member ends up as fooBar and an equivalent JSON key as foo_bar. When an API has both an imperative (IDL) and declarative (JSON) entry point, this can lead to awkward situations, as @saschanaz explains in w3c/push-api#385 (comment):

[T]he callers would have to deal with this casing in that case, like:

onpush = async (ev) => {
  // Err, our little cute browser doesn't support declarative web push,
  // so we are here for nice progressive web.
  const { notification } = await ev.data.json();
  
  // This will mostly work until you use requireInteraction.
  // await registration.showNotification(notification.title, notification);
  
  const notificationOptions = {
    ...notification,
    requireInteraction: notification.require_interaction, // 😅
  };
  await registration.showNotification(notification.title, notificationOptions);
};

I wonder it would make sense to have an exception here to prevent extra boilerplate and head-scratching?

I'm inclined to accept this inconvenience, but I wonder what other people think. We don't have that much JSON formats in the web platform so we could still change this I suspect.

Related: whatwg/infra#159.

cc @domenic @marcoscaceres @foolip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions