Can I refer to one json object in another object in the same json file?

user1124236

I'm trying to develop a test automation framework using json to describe data. I have a json file which looks like this:

{
  "preparation":{
    "configuration":[
      {
        "config1":{
          "src_configfile":"/home/xxx/etc/src_config1.cfg",
          "dest_configfile":"/home/xxx/etc/abc.cfg"
        }
      },
      {
        "config2":{
          "src_configfile":"/home/xxx/etc/src_config2.cfg",
          "dest_configfile":"/home/xxx/etc/xyz.cfg"
        }
      }
    ],
    "executable_info1":[
      {
        "login_info":{
          "hostname":"abc.dw",
          "username":"xyz",
          "password":"*******"
        }
      },
      {
        "command":{
          "folderpath":"/home/xxx/yyy/bin",
          "processname":"sys.exe",
          "parameters":"-d"
        }
      }
    ],
  },
  "execution":[
    {
      "test_case1":{
        "folderpath":"/home/xxx/testscripts",
        "scriptname":"test_case1.py",
       ***???????????Can I access the config1 object here???????????? 
       "config_file"="preparation.configuration[0].config1.dest_configfile"***
      }
    },
    {
      "test_case1":{
        "folderpath":"/home/xxx/testscripts",
        "scriptname":"test_case2.py",
        ***"config_file"="preparation.configuration[1].config2.dest_configfile"***
      }
    }
  ]
}

I need to use different config files for different test cases. Can I reference the config1 object of preparation object in the execution???

Alnitak

No, you can't do that, at least not directly. For a start, JSON doesn't support circular references.

You might consider using a library such as jsonpath that allows you to reference elements by pattern, but you would tend to need apriori whether a value was an actual value or a reference to some other branch.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add json object into another json object at the same level?

From Dev

Can I parse json either into a string or another concrete type as object?

From Dev

How can I pass the same object to another method of another object?

From Dev

Retrieving a JSON object within another one

From Dev

get another JSON object properties by given one

From Dev

How can I extract a JSON object from a CSV file in Python?

From Dev

How can I extract a JSON object from a CSV file in Python?

From Dev

converting json object in to another object

From Dev

How to get one json object format from another JSON format

From Dev

How can I move an object from one javascript file to another javascript file?

From Dev

Can different smart pointers refer to the same object?

From Dev

Can C++ reference refer to another object?

From Dev

Same object in one case, different object in another?

From Dev

how to access a JSON element when i have a value of another element in the same object?

From Dev

Transform a recursive json object to another json object

From Dev

Access a JSON Object inside another JSON Object

From Dev

Convert a JSON object to another JSON object in Java

From Dev

Accessing a JSON object inside another JSON object

From Dev

How do I pass a JSON object from one controller to another(/view to view)?

From Dev

How can I cache the JSON representation of an object?

From Dev

How can i create the json object on python?

From Dev

How can I access my JSON object?

From Dev

Convert a Json Object to a file Object

From Dev

Can i use date object as key in JSON object javascript?

From Dev

ActionListener() refer to the same object

From Dev

How can I continue a text string in a JSON object onto another line?

From Dev

How can I create a new JSON object form another using Python?

From Dev

Parse json object with another json object in string format stored in one of the properties

From Dev

Concat Same Name different Value JSON object into unique one

Related Related

  1. 1

    How to add json object into another json object at the same level?

  2. 2

    Can I parse json either into a string or another concrete type as object?

  3. 3

    How can I pass the same object to another method of another object?

  4. 4

    Retrieving a JSON object within another one

  5. 5

    get another JSON object properties by given one

  6. 6

    How can I extract a JSON object from a CSV file in Python?

  7. 7

    How can I extract a JSON object from a CSV file in Python?

  8. 8

    converting json object in to another object

  9. 9

    How to get one json object format from another JSON format

  10. 10

    How can I move an object from one javascript file to another javascript file?

  11. 11

    Can different smart pointers refer to the same object?

  12. 12

    Can C++ reference refer to another object?

  13. 13

    Same object in one case, different object in another?

  14. 14

    how to access a JSON element when i have a value of another element in the same object?

  15. 15

    Transform a recursive json object to another json object

  16. 16

    Access a JSON Object inside another JSON Object

  17. 17

    Convert a JSON object to another JSON object in Java

  18. 18

    Accessing a JSON object inside another JSON object

  19. 19

    How do I pass a JSON object from one controller to another(/view to view)?

  20. 20

    How can I cache the JSON representation of an object?

  21. 21

    How can i create the json object on python?

  22. 22

    How can I access my JSON object?

  23. 23

    Convert a Json Object to a file Object

  24. 24

    Can i use date object as key in JSON object javascript?

  25. 25

    ActionListener() refer to the same object

  26. 26

    How can I continue a text string in a JSON object onto another line?

  27. 27

    How can I create a new JSON object form another using Python?

  28. 28

    Parse json object with another json object in string format stored in one of the properties

  29. 29

    Concat Same Name different Value JSON object into unique one

HotTag

Archive