0

jsonデータをopaのオブジェクトに入れたいのですが。

その方法を説明するコメント(OPAのwebclient.Resultコンテンツの解析)を見ましたが、そのアプローチを試しましたが、アプリケーションで機能させることができません。

これが私のコードです:

type service = {
  string name,
  string kind,
  string vendor 
}
contentResult = WebClient.Get.try_get(url);
match(contentResult)
    {
    case { failure : _ }: "Error, could not connect";   
    case ~{success}:
        match (Json.deserialize(success.content)){          
                case {none}: "Error the string doesn't respect json specification";
            case {some:jsast}: match (OpaSerialize.Json.unserialize_unsorted(jsast)){
                  case {none}: "The type 'result' doesn't match jsast";
                  case {some =(value:service)}: value.name;
                  }                     
            }
    }

jsonファイルのデータを使用してservice型のオブジェクトを作成したいと思います。

最後の一致は出力に表示されるため、問題のようです

タイプ「結果」がjsastと一致しません

実際、jsonファイルには上記の3つよりも多くのキーがあります。ここにログがあります。

X Data: [
{
    "name": "redis-d80d7",
    "type": "key-value",
    "vendor": "redis",
    "version": "2.2",
    "tier": "free",
    "properties": {},
    "meta": {
        "created": 1310772000,
        "updated": 1310772000,
        "tags": [
            "redis",
            "redis-2.2",
            "key-value",
            "nosql"
        ],
        "version": 1
    }
},
JsAST: {List = [{Record = [{f1 = name; f2 = {String = redis-d80d7}}, 
{f1 = type; f2 = {String = key-value}}, {f1 = vendor; f2 = {String = redis}}, 
{f1 = version; f2 = {String = 2.2}}, {f1 = tier; f2 = {String = free}}, 
{f1 = properties; f2 = {Record = []}}, {f1 = meta; f2 = {Record = 
[{f1 = created; f2 = {Int = 1310772000}}, {f1 = updated; 
f2 = {Int = 1310772000}}, {f1 = tags; f2 = {List = [{String = redis}, 
{String = redis-2.2}, {String = key-value}, {String = nosql}]}}, 
{f1 = version; f2 = {Int = 1}}]}}]}
4

0 に答える 0