mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Fixing special character example
This commit is contained in:
		
							parent
							
								
									b702686891
								
							
						
					
					
						commit
						e76a2f3de6
					
				@ -33,7 +33,7 @@ c: banana
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Special characters
 | 
			
		||||
Use quotes around path elements with special characters
 | 
			
		||||
Use quotes with brackets around path elements with special characters
 | 
			
		||||
 | 
			
		||||
Given a sample.yml file of:
 | 
			
		||||
```yaml
 | 
			
		||||
@ -41,7 +41,7 @@ Given a sample.yml file of:
 | 
			
		||||
```
 | 
			
		||||
then
 | 
			
		||||
```bash
 | 
			
		||||
yq eval '."{}"' sample.yml
 | 
			
		||||
yq eval '.["{}"]' sample.yml
 | 
			
		||||
```
 | 
			
		||||
will output
 | 
			
		||||
```yaml
 | 
			
		||||
 | 
			
		||||
@ -47,13 +47,21 @@ var traversePathOperatorScenarios = []expressionScenario{
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
		description:    "Special characters",
 | 
			
		||||
		subdescription: "Use quotes around path elements with special characters",
 | 
			
		||||
		subdescription: "Use quotes with brackets around path elements with special characters",
 | 
			
		||||
		document:       `{"{}": frog}`,
 | 
			
		||||
		expression:     `."{}"`,
 | 
			
		||||
		expression:     `.["{}"]`,
 | 
			
		||||
		expected: []string{
 | 
			
		||||
			"D0, P[{}], (!!str)::frog\n",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
		skipDoc:    true,
 | 
			
		||||
		document:   `{"flying fox": frog}`,
 | 
			
		||||
		expression: `.["flying fox"]`,
 | 
			
		||||
		expected: []string{
 | 
			
		||||
			"D0, P[flying fox], (!!str)::frog\n",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
		description:    "Dynamic keys",
 | 
			
		||||
		subdescription: `Expressions within [] can be used to dynamically lookup / calculate keys`,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user