I would like put the json data in a object in opa.
I saw a comment ( parsing a webclient.Result content in OPA ) which describes how to do that but I tried that approach and can't make it work with my application.
Here's my code :
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;
}
}
}
I want to create an object of type service with the data from the json file.
The last match seems to be a problem because it displays in output
The type 'result' doesn't match jsast
In fact, i have more keys in my json file than this 3 above, here my log:
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}}]}}]}