JObject Config has bad practice in the JSON format

Upon writing an Editor tool to fetch values from the Unity Remote Config System using RemoteConfigWebApiClient.FetchConfigs() I noticed that in the JSON format there are two different keys with the same name : “value”.

Here is the JSON :

{
"type": "settings",
"value": [
{
"key": "Test JSON",
"type": "json",
"schemaId": "test-schema",
"value": [
{
"Parameter": "Param1",
"Value": "Val1"
},
{
"Parameter": "Param2",
"Value": "Val2"
},
{
"Parameter": "Param2",
"Value": "Val2"
}
]
},
{
"key": "TestMe",
"type": "string",
"value": "BakedValue"
},
{
"key": "TestMe2",
"type": "string",
"value": "Baked Value V2\n"
}
]
}

As you can see, there is a “value” entry related to the overall config and a “value” entry for each key in the config. This creates issues when parsing the JObject. They are solvable, but it doesn’t feel clean.

Am I missing something?

Hi,

What version of the package are you using? It seems you’re using unintentionally using the admin API?
This api is used at edition time.

It’ll be easier to help if I could understand both what you are trying to achieve, and what errors you’re facing.

Here’s what an example of using the runtime:

var res = await RemoteConfigService.Instance.FetchConfigsAsync(new EmptyStruct(), new EmptyStruct());

var testMe = res.config["TestMe"].ToObject<string>;

if your JObject looks like that from the administrative API,
you can build a model for it, or just just fish for it with the jobject:

var param1Str = jObj["value"][0]["value"]["value"][0]["Value"]

But im unsure of the use-case, if you’re looking for an editor integration to modify RC, look into this:

1 Like

Hey,

Indeed, I am using the Admin API. I have an editor tool that needs to fetch the remote config data whilst not being in play mode.

I was able to parse the JSON, no problem. The problem is that in a JSON there should never be two keys with the same name.

Thanks for the reply!

Hey!
I’m not so sure about that, where did you get that from?
This is perfectly valid json:

{
"key" : {"key" :  { "key" : "value" } }
}

Verified with this: https://jsonlint.com/

This is invalid though:

{
"key" : {"key" :  { "key" : "value" } },
"key" : "value"
}

though most parsers will just take the latest value as an override.

I double checked and the json you provided that RC admin is returning is indeed valid according to jsonlint.

May I enquire as what you are trying to do with the admin API?
it may give some guidance with features we’re working on.

Cheers!

1 Like

Hey!

I was not talking about the fact that it is invalid. When I said that in a JSON there should never be two keys with the same name I was refering strictly design wise. It is confusing and not generally clean.

I am updating some local scriptable objects with values from the server (therefore I need to use the Admin API). Thanks for your help, I got it to work!

Hi there, a quick question that’s perhaps related to this.
I am making a web API call to update a configId. I was partially successful.
the configurations that are not objects had no problems being updated. but, for object ones, the API accepted it, but it looks like it didnt update it at all. I tested it several times and only the non object/json stuff are being updated.

I think there isnt a need to share here the exact config/format that im sending given that I am successful in updating some data but not all, i guess implies there isnt anything wrong with the header, endpoint etc.
the body I am sending here:
9799077--1406550--upload_2024-4-26_20-14-59.png