Ironclad / rivet

The open-source visual AI programming environment and TypeScript library
https://rivet.ironcladapp.com
MIT License
2.56k stars 226 forks source link

[Bug]: "JSON strings" #307

Closed mindplay-dk closed 5 months ago

mindplay-dk commented 5 months ago

What happened?

I believe I've managed to isolate a fundamental data type issue with JSON values - have a look at this:

image

as you can see, from top to bottom:

  1. A "JSON array" of "JSON strings" converts into a single string with multiple quoted strings.
  2. if we split the values, the "JSON strings" individually convert into quoted strings.
  3. the "to JSON" node is able to convert a "JSON array" or "JSON strings" back into JSON just fine.

now contrast that example with this one:

image

as you can see, from top top bottom:

  1. a "regular array" of "regular strings" converts into a single string with line-breaks but no quotes.
  2. if we split the values, "regular strings" convert into plain strings without any quotes.
  3. the "to JSON" node handles "regular strings/arrays" the same as "JSON strings/array".

It looks like this might be a symptom of "leaky" underlying JSON wrapper data types?

Here is the example project for reference: JSON-strings.zip

What was the expected functionality?

Strings and arrays should behave the same everywhere.

Describe your environment

Win 11 Pro

Relevant log output

No response

Relevant screenshots

No response

Code of Conduct

codemile commented 5 months ago

I don't think Object knows it's outputting a collection. Technically, in JavaScript an Array is an Object. We use named data types in Rivet (meaning, there is a string representation for that type). As a result, the Text node is just reading that string which says it's an Object type. The output is probably just a side effect of that object being a collection.

This might be easily fixed by having the Object node inspect the data for being an Array and outputting the appropriate type string.

Fyi, I'm just guessing here.

mindplay-dk commented 5 months ago

This might be easily fixed by having the Object node inspect the data for being an Array and outputting the appropriate type string.

You can't inspect the data until there's data though...?

abrenneke commented 5 months ago

It's actually because we end up with a type

{
  "type": "object",
  "value": "foo",
}

So it's JSON.stringifying the value. I think if we more intelligently format object values this will be improved.