You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							30 lines
						
					
					
						
							654 B
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							30 lines
						
					
					
						
							654 B
						
					
					
				| #include <json.hpp> | |
|  | |
| using json = nlohmann::json; | |
| 
 | |
| int main() | |
| { | |
|     // the original document | |
|     json doc = R"( | |
|         { | |
|           "baz": "qux", | |
|           "foo": "bar" | |
|         } | |
|     )"_json; | |
| 
 | |
|     // the patch | |
|     json patch = R"( | |
|         [ | |
|           { "op": "replace", "path": "/baz", "value": "boo" }, | |
|           { "op": "add", "path": "/hello", "value": ["world"] }, | |
|           { "op": "remove", "path": "/foo"} | |
|         ] | |
|     )"_json; | |
| 
 | |
|     // apply the patch | |
|     json patched_doc = doc.patch(patch); | |
| 
 | |
|     // output original and patched document | |
|     std::cout << std::setw(4) << doc << "\n\n" | |
|               << std::setw(4) << patched_doc << std::endl; | |
| }
 |