Skip to content

Commit d604339

Browse files
docs: document JsonValue construction in readme (#292)
1 parent 8422a28 commit d604339

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ FileCreateParams params = FileCreateParams.builder()
302302
FileObject fileObject = client.files().create(params);
303303
```
304304

305-
Note that when passing a non-`Path` its filename is unknown so it will not be included in the request. To manually set a filename, pass a `MultipartField`:
305+
Note that when passing a non-`Path` its filename is unknown so it will not be included in the request. To manually set a filename, pass a [`MultipartField`](openai-java-core/src/main/kotlin/com/openai/core/Values.kt):
306306

307307
```java
308308
import com.openai.core.MultipartField;
@@ -608,7 +608,7 @@ ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
608608

609609
These properties can be accessed on the nested built object later using the `_additionalProperties()` method.
610610

611-
To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](openai-java-core/src/main/kotlin/com/openai/core/JsonValue.kt) object to its setter:
611+
To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](openai-java-core/src/main/kotlin/com/openai/core/Values.kt) object to its setter:
612612

613613
```java
614614
import com.openai.core.JsonValue;
@@ -620,6 +620,45 @@ ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
620620
.build();
621621
```
622622

623+
The most straightforward way to create a [`JsonValue`](openai-java-core/src/main/kotlin/com/openai/core/Values.kt) is using its `from(...)` method:
624+
625+
```java
626+
import com.openai.core.JsonValue;
627+
import java.util.List;
628+
import java.util.Map;
629+
630+
// Create primitive JSON values
631+
JsonValue nullValue = JsonValue.from(null);
632+
JsonValue booleanValue = JsonValue.from(true);
633+
JsonValue numberValue = JsonValue.from(42);
634+
JsonValue stringValue = JsonValue.from("Hello World!");
635+
636+
// Create a JSON array value equivalent to `["Hello", "World"]`
637+
JsonValue arrayValue = JsonValue.from(List.of(
638+
"Hello", "World"
639+
));
640+
641+
// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
642+
JsonValue objectValue = JsonValue.from(Map.of(
643+
"a", 1,
644+
"b", 2
645+
));
646+
647+
// Create an arbitrarily nested JSON equivalent to:
648+
// {
649+
// "a": [1, 2],
650+
// "b": [3, 4]
651+
// }
652+
JsonValue complexValue = JsonValue.from(Map.of(
653+
"a", List.of(
654+
1, 2
655+
),
656+
"b", List.of(
657+
3, 4
658+
)
659+
));
660+
```
661+
623662
### Response properties
624663

625664
To access undocumented response properties, call the `_additionalProperties()` method:

0 commit comments

Comments
 (0)