Welcome to WSL!

New to the forum? Please read this and this.

JSON Reader  [SUBMITTED]

Moderator: SecondMan

User avatar
bfloch
Fusioneer
Posts: 103
Joined: Wed Aug 06, 2014 4:25 pm
Been thanked: 4 times

JSON Reader  [SUBMITTED]

#1

Post by bfloch »

com.bfloch.JSONReader.zip
A modifier that picks a value from a JSON File. Why does this not exist yet? No idea.

Usage

Given a JSON dataset like:

Code: Select all

{
   "dataset": {
        "metadata": ["Hello", "World"]
   }
}
... loaded from a file, and a Key set to:

Code: Select all

dataset.metadata.2
... results in the value "World". Note that arrays indices begin with 1, like with Lua, not 0.

Array access via Frames

You can access arrays based on frame number by making the Key input a SimpleExpression like:

Code: Select all

Text("dataset.metadata." .. time)
Notes

In order to access keys with . the separator can be changed.
If the JSON file can not be loaded, or the field is not found a default value can be supplied. It will be returned as fallback by the modifier.

P.S. Reactor and Atomizer is just mind blowing!
You do not have the required permissions to view the files attached to this post.

User avatar
Kristof
Fusionista
Posts: 880
Joined: Thu Aug 07, 2014 1:30 pm
Answers: 5
Been thanked: 1 time

Re: JSON Reader

#2

Post by Kristof »

I did create a reader a while ago but it's not part of Reactor.

User avatar
bfloch
Fusioneer
Posts: 103
Joined: Wed Aug 06, 2014 4:25 pm
Been thanked: 4 times

Re: JSON Reader

#3

Post by bfloch »

Cool, Kristof. Let me know if you miss any particular function.

Added in 1 minute 37 seconds:
One thing I should mention - I decided to use an hidden input for the parsed JSON file. That means that the whole JSON file will be stored within the comp, which might be an overkill. The alternative would be using global variables, but it did not work for me for some reason to write into a variable in the NotifyChange callback and and read in the Process. Any ideas?

User avatar
tida
Fusioneer
Posts: 180
Joined: Mon Jan 27, 2020 4:37 am
Answers: 1
Real name: none
Been thanked: 18 times

Re: JSON Reader

#4

Post by tida »

Not a reader, but a library:
http://dkolf.de/src/dkjson-lua.fsl/home
Was already used here:
viewtopic.php?f=45&t=1727

User avatar
bfloch
Fusioneer
Posts: 103
Joined: Wed Aug 06, 2014 4:25 pm
Been thanked: 4 times

Re: JSON Reader

#5

Post by bfloch »

Had no idea it's a community project. I'm using dkjson - stole the snippet from Cryptomatte. Thanks so much.

User avatar
SecondMan
Site Admin
Posts: 4825
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 31
Location: Vancouver, Canada
Been thanked: 32 times
Contact:

Re: JSON Reader

#6

Post by SecondMan »

Thanks for your first submission, @bfloch :cheer:

Available in Reactor now :)