mlld
Version:
mlld: llm scripting language
30 lines (25 loc) • 960 B
Markdown
---
id: file-loading-json-accessors
title: JSON String Accessors
brief: Parse JSON strings with .data and stringify with .text
category: syntax
parent: file-loading
tags: [json, parsing, strings]
related: [pipelines-basics, variables-basics]
related-code: [interpreter/eval/field-access.ts]
updated: 2026-01-05
---
**JSON string accessors** (`.data` and `.text`):
```mlld
>> When you have a JSON string and need to parse it
var = '[{"name":"Alice"},{"name":"Bob"}]'
var = .data >> parses JSON string to array/object
show .0.name >> "Alice"
>> When you have an object and need the JSON string
var = {"name": "Alice"}
var = .text >> stringified JSON
show >> '{"name":"Alice"}'
>> Common in pipelines with LLM responses
var = | .llm
var = .data >> if response is JSON string
```