How do I use JSON deeper?

0 favourites
  • 4 posts
From the Asset Store
Excel2JSON
$1.20 USD
60% off
Convert multiple Excel files into JSON files and import them into construct3.
  • I have a JSON file similar to the following:

    {
     "data": [
    	 {
    	 "name": "Bob",
    	 "condition": {
    		 "health": "100",
    		 "married": "yes",
    		 "age": "34",
    		 }
    	 }
     ]
    }
    

    I understand that I can do:

    For Each data
    	For Each .name - JSON.CurrentValue
    

    But I can't quite figure out how to get a specific lower value. For example, I'd have thought:

    For Each data
    	For Each .condition
    		For Each .age - JSON.CurrentValue
    

    Would work... but it doesn't. It all comes up blank.

    If I do:

    For Each data
    	For Each .condition - JSON.CurrentValue
    

    It'll post "100, yes 34" to me, but how do I specifically grab just the one I want?

    In the manual it suggests I do ".condition.age - JSON.CurrentValue"

    But that doesn't work either. Kinda at a loss here...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You have to do:

    For Each data - JSON.Get(".condition.age")
    

    This will get the age etc.

  • Chech out this demo:

    dropbox.com/s/srgf9lme08by9wa/JSON-RecursiveRead.c3p

    I find it quite useful - it shows full paths for all keys in JSON.

  • dop2000

    Thanks for posting this project file. I've been learning how to implement JSON in my project and used Book project file to learn the structure of a JSON file. The link you posted here will be a major jump in my understanding how to set paths, Get, and Set JSON values.

    It's hard to visualize my JSON file's path when its 3 levels deep. I've learn to Get values but I'm having a hard time getting a set KEY values. Half the time it is my visual impairment causing typos and the understanding the pathing process. This definitely helps my progress in using JSON file in my project.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)