portal

Andriy Levitskyy 2025-04-26T17:49:50.030879Z

Hi, So I tried to add metadata to JSON requests to Portal /submit endpoint, so that Portal Viewers can be specified even with JSON encoding, and got something hacky working for my use-case (sending JSON Vega-Lite specs from C++) https://github.com/ALevitskyy/portal/pull/1 The problems I encountered: 1. Metadata being thrown away when JSON-encoding -> Solution: Encode all values with metadata as {meta_ metadata, data_ value} 2. Some metadata has keywords as values -> Solution: Convert each keyword as string and prepend "__portal__runtime__json__keyword__" to them Problems with my approach 1. Slower encoding-decoding: currently the parser walks input JSON 3 times when decoding to convert all the keys and values 2. Need to add weird additional keys and substrings to JSON (easily automated on client though) When I send the JSON below, the Portal automatically selects Vega-Lite viewer: "{\"portal.runtime.json\\/meta__\":{\"portal.viewer\\/default\":\"__portal__runtime__json__keyword__portal.viewer\\/vega-lite\"}, \"portal.runtime.json\\/data__\": {\"$schema\":\"\", \"data\":{ \"values\":[ {\"category\":\"A\",\"value\":28}, {\"category\":\"B\",\"value\":55}, {\"category\":\"C\",\"value\":43}, {\"category\":\"D\",\"value\":91}, {\"category\":\"E\",\"value\":81} ] }, \"mark\":\"bar\", \"encoding\":{ \"x\":{\"field\":\"category\",\"type\":\"nominal\",\"axis\":{\"labelAngle\":0}}, \"y\":{\"field\":\"value\",\"type\":\"quantitative\"} } }}"