Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set JSON object value as referred by another key:value pair in the same file [duplicate]

Tags:

json

In a JSON file, how to set object value that is referred by another key : value pair in the same JSON file, (not in JAVA / any programming language).

    "FRUIT_A":"Watermelon",
    "FRUIT_B":"Mango",
    "FRUIT_C":"Apple",
    "FRUIT_D":"Grape",
    
    // How to set the value with reference of another key.value.
    "BIGGEST_FRUIT": ${FRUIT_A},  // <-- just a reference to explain what I want to achieve. 
    "SMALLEST_FRUIT": ${FRUIT_D}, // <-- another ref, don't know what notation. 

Not sure, if it is possible to do within JSON file itself. From above example, I basically want to set the values of keys as below:

    "BIGGEST_FRUIT": "Watermelon",  
    "SMALLEST_FRUIT": "Grape",
like image 466
Khulja Sim Sim Avatar asked Sep 15 '25 14:09

Khulja Sim Sim


1 Answers

JSON is a simple text based file which stores data in key value format. If you want to refer value of another key then there has to be some resolver which will resolve the reference and provide you the expected value.

If you would like to know more on Please checkout this link

like image 136
Nagesh Chauhan Avatar answered Sep 18 '25 12:09

Nagesh Chauhan