Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback JObject Config has bad practice in the JSON format

Discussion in 'Unity Remote Config' started by alex11paulescu, Apr 6, 2024.

  1. alex11paulescu

    alex11paulescu

    Joined:
    Sep 6, 2021
    Posts:
    22
    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?
     
  2. GabKBelmonte

    GabKBelmonte

    Unity Technologies

    Joined:
    Dec 14, 2021
    Posts:
    150
    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:
    Code (CSharp):
    1. var res = await RemoteConfigService.Instance.FetchConfigsAsync(new EmptyStruct(), new EmptyStruct());
    2.  
    3. 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:

    Code (CSharp):
    1. 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:
    https://forum.unity.com/threads/remote-config-authoring-tool-from-the-editor-pre-release.1353494/
     
    vd_unity likes this.
  3. alex11paulescu

    alex11paulescu

    Joined:
    Sep 6, 2021
    Posts:
    22
    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!
     
  4. GabKBelmonte

    GabKBelmonte

    Unity Technologies

    Joined:
    Dec 14, 2021
    Posts:
    150
    Hey!
    I'm not so sure about that, where did you get that from?
    This is perfectly valid json:

    Code (CSharp):
    1. {
    2. "key" : {"key" :  { "key" : "value" } }
    3. }
    Verified with this: https://jsonlint.com/

    This is invalid though:

    Code (CSharp):
    1. {
    2. "key" : {"key" :  { "key" : "value" } },
    3. "key" : "value"
    4. }
    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!
     
    vd_unity likes this.
  5. alex11paulescu

    alex11paulescu

    Joined:
    Sep 6, 2021
    Posts:
    22
    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!
     
  6. Boozeman

    Boozeman

    Joined:
    Nov 2, 2023
    Posts:
    1
    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:
    upload_2024-4-26_20-14-59.png